r-将误差线添加到xyplot中的不同组 [英] r- Add error bars to different groups in xyplot
问题描述
我对R还是很陌生,所以希望你们能帮助我解决这个问题.我试图寻找其他类似问题的帖子,但找不到任何帖子.
I'm quite new to R, so I hope you guys can help me out with this problem. I tried to look for other posts with similar questions, but wasn't able to find any.
这是我的代表数据集的构造方式:
This is how my representative data set is constructed:
library(lattice)
data(Theoph)
DF <- Theoph
DF$Time <- rep(c(0,0.25,0.5,1,2,4,5,7,9,12,24), times=12)
DF$group[DF$Subject==1|DF$Subject==2|DF$Subject==3] <- "A"
DF$group[DF$Subject==4|DF$Subject==5|DF$Subject==6] <- "B"
DF$group[DF$Subject==7|DF$Subject==8|DF$Subject==9] <- "C"
DF$group[DF$Subject==10|DF$Subject==11|DF$Subject==12] <- "D"
y <- DF$conc
x <- DF$Time
groups <- as.factor(DF$group)
我使用以下代码制作了一个xyplot,它显示了各个数据点,还显示了每组平均值(A,B,C和D)的线:
I made an xyplot that shows the individual data points and also lines showing the mean per group (A,B,C and D) using this code:
xyplot(y ~ x, type="p", groups=groups, auto.key=T,
panel = function(x, y, groups, subscripts, ...){
panel.superpose(x, y, groups, subscripts,...,
panel.groups=function(x,y,col,col.symbol,...){
panel.xyplot(x, y, col=col.symbol,...)
panel.average(x, y, col=col.symbol, lwd = 2, horizontal = FALSE)
})
})
我想在平均值上加上误差线(例如+/-标准偏差).我知道有一个名为panel.arrows的函数,但是我没有成功将其与panel.groups函数结合使用.
I would like to add error bars (e.g. +/- standard deviation) to the mean values. I know there is a function called panel.arrows, but I haven't been successful in combining it with the panel.groups function.
有什么办法吗?还是我应该先制作一个带有SD以及误差线上下限的单独数据帧?
Is there any way of doing this? Or should I make a separate data frame first with the SD and lower and upper limits of the error bars?
推荐答案
This may not be exactly what you were looking for, but it comes very close. Have a read here: R - Lattice xyplot - How do you add error bars to groups and summary lines?
这篇关于r-将误差线添加到xyplot中的不同组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!