我怎么能用兩個不同的y軸來畫圖呢?我想在R中疊加兩個散點圖,這樣每一組點都有自己的(不同的)y軸(即在圖的位置2和4中),但是這些點似乎疊加在相同的圖形上。能不能用plot?編輯顯示問題的示例代碼# example code for SO questiony1 <- rnorm(10, 100, 20)y2 <- rnorm(10, 1, 1)x <- 1:10# in this plot y2 is plotted on what is clearly an inappropriate scaleplot(y1 ~ x, ylim = c(-1, 150))points(y2 ~ x, pch = 2)
3 回答

慕姐4208626
TA貢獻1852條經(jīng)驗 獲得超7個贊
ggplot2
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")
- 3 回答
- 0 關(guān)注
- 695 瀏覽
添加回答
舉報
0/150
提交
取消