首页 > 解决方案 > ggplot:根据截距和斜率填充两个geom_abline之间的空间

问题描述

你将如何用两条红线之间的颜色填充空间?

阴谋

这是我根据 Lavaan 的因子分数从我的增长图数据框中提取的片段:

ID  Time Variable   Intercept   Slope
1   1   -0.37924496 -0.43277857 -0.0158650869
2   1   -1.84909928 -1.62877855 0.3286621872
3   1   -0.65797366 -0.78597746 0.4031575259
4   2   -2.17330430 -1.82634938 0.0785367542
5   2   0.21736195  0.53714145  0.9338908763
6   2   1.77226804  1.33300399  0.3201886213
7   3   -2.50918298 -2.26727709 -0.0447654125
8   3   0.78092414  0.80472772  0.2120721960
9   3   -1.21900810 -0.62373325 0.9764875664
10  3   -0.91656612 -0.91447864 -0.3120689584

我从估计的截距和斜率中手动添加了一个数据框及其置信区间:

growthdf <- data.frame(Intercept = c(-0.074), Slope = c(0.133), i.ci.low = c(-0.173), i.ci.up = c(0.024), s.ci.low = c(0.048), s.ci.up = c(0.218))

到目前为止,这是我的 ggplot:

ggplot(growthplot, aes(x = Time, y = Construct)) +
geom_point(alpha=.0) +
geom_abline(aes(intercept = Intercept, slope = Slope), data = growthplot,alpha=.05) +
geom_abline(aes(intercept = Intercept, slope = Slope), data = growthdf,alpha=1) +
geom_abline(aes(intercept = i.ci.low, slope = s.ci.low), data = growthdf,alpha=1, color="red") +
geom_abline(aes(intercept = i.ci.up, slope = s.ci.up), data = growthdf,alpha=1, color="red")

标签: rggplot2intercept

解决方案


推荐阅读