【发布时间】:2023-03-28 12:04:01
【问题描述】:
我正在尝试使用xYplot from package Hmisc 绘制覆盖在抖动的原始数据点上的误差线。使用panel.stripplot 调用xYplot 中的函数似乎很简单。它有效,但有一个奇怪的故障 - 我不能“抖动”用panel.stripplot 绘制的数据。让我说明一下我的观点:
library(reshape2)
library(Hmisc)
data(iris)
#get error bars
d <- melt(iris, id=c("Species"), measure=c("Sepal.Length"))
X <- dcast(d, Species ~ variable, mean)
SD <- dcast(d, Species ~ variable, sd)
SE = SD[,2]/1#this is wrong on purpose, to plot larger error bars
Lo = X[,2]-SE
Hi = X[,2]+SE
fin <- data.frame(X,Lo=Lo,Hi=Hi)
#plot the error bars combined with raw data points
quartz(width=5,height=7)
xYplot(Cbind(Sepal.Length, Lo, Hi) ~ numericScale(Species), fin,
type=c("p"), ylim=c(4,8),lwd=3, col=1,
scales = list(x = list(at=1:3, labels=levels(d$Species))),
panel = function(x, y, ...) {
panel.xYplot(x, y, ...)
panel.stripplot(d$Species, d$value, jitter.data = TRUE, cex=0.2, ...)
}
)
结果:
如您所见,这些点与误差线垂直排列,为什么我希望它们在水平平面中稍微偏移。我试图调整panel.stripplot 中的factor 和amount 参数,但它并没有改变它。有什么建议么?请仅使用格子的解决方案,最好使用xYplot。
【问题讨论】: