我知道有很多类似的问题,但我无法找到问题的答案。每组和每天的观察数应写在百分比条形图的底部(!),如本例所示。
我不知道如何做到这一点。
我的数据框:
day cohort n mean se
1 1 CLOSED 70 47.66 26.63
2 2 CLOSED 70 60.19 23.72
3 3 CLOSED 67 65.68 23.16
4 4 CLOSED 60 67.96 21.38
5 1 OPEN 66 31.45 31.59
6 2 OPEN 66 39.83 25.76
7 3 OPEN 61 38.53 24.06
8 3 OPEN 52 45.23 25.00
....
我的代码:
p2 <- ggplot(data = df2, aes(x = day, y = mean, fill = cohort))
p2 + geom_bar(stat = "identity",
color = "black",
position = position_dodge(0.9),
size = 1) +
geom_text(aes(label = n),
color = "black",
size = 3.5,
position = position_dodge(width=0.9),
vjust = 1.5) +
labs(x = "Day",
y = "Time in target range (%)")