How can I plot with 2 different y-axes?

前端 未结 6 1349
遥遥无期
遥遥无期 2020-11-22 08:46

I would like superimpose two scatter plots in R so that each set of points has its own (different) y-axis (i.e., in positions 2 and 4 on the figure) but the points appear su

6条回答
  •  广开言路
    2020-11-22 09:18

    One option is to make two plots side by side. ggplot2 provides a nice option for this with facet_wrap():

    dat <- data.frame(x = c(rnorm(100), rnorm(100, 10, 2))
      , y = c(rnorm(100), rlnorm(100, 9, 2))
      , index = rep(1:2, each = 100)
      )
    
    require(ggplot2)
    ggplot(dat, aes(x,y)) + 
    geom_point() + 
    facet_wrap(~ index, scales = "free_y")
    

提交回复
热议问题