我想将中值样条曲线和相应的置信区间带添加到ggplot2
散点图中。我正在使用'quantreg'-package,更具体地说是rqss
函数(Additive Quantile Regression Smoothing)。
在ggplot2
我可以添加中值样条,但不能添加置信区间带:
fig = ggplot(dd, aes(y = MeanEst, x = N, colour = factor(polarization)))
fig + stat_quantile(quantiles=0.5, formula = y ~ qss(x), method = "rqss") +
geom_point()
-packagequantreg
自带绘图功能;plot.rqss
. 我可以在哪里添加置信带(bands=TRUE
):
plot(1, type="n", xlab="", ylab="", xlim=c(2, 12), ylim=c(-3, 0)) # empty plot
plotfigs = function(df) {
rqss_model = rqss(df$MeanEst ~ qss(df$N))
plot(rqss_model, bands=TRUE, add=TRUE, rug=FALSE, jit=FALSE)
return(NULL)
}
figures = lapply(split(dd, as.factor(dd$polarization)), plotfigs)
但是 -package 附带的绘图功能quantreg
不是很灵活/很适合我的需要。是否有可能在ggplot2
情节中获得置信带?也许通过模仿 -package 中使用的方法quantreg
,或者只是从情节中复制它们?
数据:pastebin。