R ggplot散点图和带误差的平均值

时间:2017-06-08 03:41:47

标签: r ggplot2

我想用误差线生成散点图和平均值。我的代码如下。当我添加geom_errorbar()时,会出现错误消息:

  

FUN中的错误(X [[i]],...):对象'值'找不到

Z <- c(.1,.5,1.)
T <- seq(1:10)
ZT <- expand.grid(Z,T)
colnames(ZT) <- c("Z","T")

n <- nrow(ZT)

nrep <- 100

rmat <- replicate(nrep, rnorm(n))

ave <- apply(rmat,1,mean)
var <- apply(rmat,1,var)
se <- sqrt(var)/sqrt(nrep)

rmat.summary <- as.data.frame(cbind(ZT,ave,se))
colnames(rmat.summary) <- c("Z","T","ave","se") 

library(reshape)
library(ggplot2)


rmat <- as.data.frame(cbind(ZT,rmat))
rmat <- melt(as.data.frame(rmat),id=c(1,2))

ggplot(rmat, aes(x = T, y = value)) + geom_point() + geom_line(data =         
  rmat.summary, aes(x = T, y = ave)) + facet_wrap( ~ Z)

ggplot(rmat, aes(x = T, y = value)) + geom_point() + geom_line(data = 
  rmat.summary, aes(x = T, y = ave)) + 
  geom_errorbar(data = rmat.summary, aes(ymin = ave - se, ymax = ave + se)) 
  + facet_wrap( ~ Z)

那么有人可以帮我纠正这个错误吗?提前致谢!

1 个答案:

答案 0 :(得分:0)

这应该有效:

find_one( {'text': {'$regex': "/^RT.*/" } }  )

但我认为你必须使用ggplot() + geom_point(data = rmat, aes(x = T, y = value)) + geom_line(data = rmat.summary, aes(x = T, y = ave)) + geom_errorbar(data = rmat.summary, aes(x = T, y = ave, ymin = ave - se, ymax = ave + se)) + facet_wrap( ~ Z) ymin

相关问题