我有一个用格子的xyplot生成的线图。它包含两种测量温度,其中一种是平均值。因此,我想为这些点添加标准错误(t.tort)。不幸的是,单独执行此操作无法使用(Hmisc)errbar ...这是我到目前为止所提出的:
xyplot(mean.tort+t.ws~DateTime, pre, type=c("a", "p"), col=c("red", "blue"),
main="Pre-Translocation",
xlab=list(label="Date and Time", cex=1),
ylab=list(label="Temperature (°C)", cex=1),
scales = list(tck = c(1, 0),
x=list(cex=0.8, rot=45, tick.number=40),
y=list(cex=0.8, tick.number=8, limits=c(29,43))),
key=list(text=list(c("Tortoise","Ambient")), lines=list(col=c("red", "blue"),type="l"), corner=c(0.5,0.92)))
errbar(x=pre$DateTime, y=pre$mean.tort, yplus=pre$mean.tort+pre$se.tort,yminus=pre$mean.tort-pre$se.tort,
add=T, col="red")
我数据框的重要部分如下:
pre$DateTime<-c(as.POSIXct("2013-01-27 09:00:00" "2013-01-27 10:00:00" "2013-01-27 11:00:00" "2013-01-27 12:00:00" "2013-01-27 13:00:00")
pre$t.ws<-c(32.7, 35.5, 37.1, 37.6, 38.7)
pre$mean.tort<-c(32.4, 34.9, 35.1, 36.8, 37.7)
pre$se.tort<-c(0.825, 0.84, 0.21, 0.228, 0.28)
我对此感到有点沮丧,因此任何建议都会受到很大的影响。 非常感谢你提前做出的努力!
答案 0 :(得分:1)
试试这个
您的数据:
pre = data.frame(DateTime = as.POSIXct(c("2013-01-27 09:00:00", "2013-01-27 10:00:00",
"2013-01-27 11:00:00", "2013-01-27 12:00:00",
"2013-01-27 13:00:00")),
t.ws = c(32.7, 35.5, 37.1, 37.6, 38.7),
mean.tort = c(32.4, 34.9, 35.1, 36.8, 37.7),
se.tort = c(0.825, 0.84, 0.21, 0.228, 0.28))
情节:
require(lattice)
xyplot(mean.tort+t.ws~DateTime, pre,
main="Pre-Translocation",
xlab=list(label="Date and Time"),
ylab=list(label="Temperature (°C)"),
scales = list(tck = c(1, 0),
x=list(cex=0.8, rot=45, tick.number=40),
y=list(cex=0.8, tick.number=8, limits=c(29,43))),
key=list(text=list(c("Tortoise","Ambient")),
lines=list(col=c("red", "blue"),
type="l"), corner=c(0.5,0.92)),
lx = pre$mean.tort - pre$se.tort, ux = pre$mean.tort + pre$se.tort,
panel = function (x,y, lx, ux, ...){
panel.xyplot(x,y, type = "b", col=c("red", "blue"), ...)
panel.segments(x0 = x, x1 = x, y0 = lx, y1 = ux, col = "red", ...)
}
)
在这里:
如果您真的想在错误栏上放置那些小“帽子”,可以使用panel.arrows()
代替细分。