我想使用上限和下限列为ggplot创建一个“灰色” geom_smooth(或其他变体)。数据如下:
data <- read.table(text="
Student Month TestScore LowestScore HighestScore MeanTest
001 1 65 44 97 77
001 2 75 38 92 78
001 3 80 58 99 79
002 1 83 44 97 77
002 2 76 38 92 78
002 3 85 58 99 79", header=TRUE)
所以我想每月绘制受试者的考试成绩,然后在背景中为总考试成绩(不是这两个受试者)单独设置一个“灰色”置信度。
到目前为止,我对这两个主题有以下情节:
ggplot(data = data, aes(x = Month, y = TestScore, group = TestScore, color = Student)) +
geom_point() +
geom_line() +
theme_bw()
任何见识将不胜感激。
答案 0 :(得分:0)
您描述的不是置信区间,而是每个月的数据范围。如果要以geom_smooth
的置信区间样式绘制此范围,可以执行以下操作:
(我不确定在建议的绘图中按TestScore进行分组是什么。)
ggplot(data = data, aes(x = Month, y = TestScore, color = Student, group = Student)) +
geom_ribbon(aes(ymin = LowestScore, ymax = HighestScore), fill = "grey70", alpha = 0.3, color = NA) +
geom_point() +
geom_line() +
theme_bw()