在水平图上叠加xyplot,在R

时间:2016-09-19 17:46:48

标签: r plot ggplot2 lattice

假设我有这两个数据集:

dat <- data.frame("year"= c(2000:2005),"X1"=runif(6,-3,3),"X2"=runif(6,-3,3),"X3"=runif(6,-3,3),"X4"=runif(6,-3,3),"X5"=runif(6,-3,3),"X6"=runif(6,-3,3),"X7"=runif(6,-3,3),"X8"=runif(6,-3,3),"X9"=runif(6,-3,3),"X10"=runif(6,-3,3),"X11"=runif(6,-3,3),"X12"=runif(6,-3,3))

newd <- data.frame("year"=c(2000:2005), "val"=c(40,45,50,35,40,55), "sd"=c(5,6,8,4,5,9))

我想在第一个数据集上绘制第二个数据集,因此它们都有共同的x轴但是y轴不同。 以下是使用lattice levelplot函数绘制第一个数据集的方法:

library(lattice)
idx <- c(1:12)
dat2 <- expand.grid(y=dat[,1], x=idx)
dat2$z <- as.vector(as.matrix(dat[,-1]))
levelplot(z ~ y*x, data=dat2)

enter image description here

我感谢任何关于newd数据,x=year轴和新y轴覆盖value变量的标准偏差带sd的建议。< / p>

0 个答案:

没有答案