我正在尝试使用 geom_text 来标记位置 =“填充”的多面 geom_col 图。
这是我正在使用的数据的简化版本:
group = c("Group1", "Group1", "Group1", "Group1", "Group1", "Group1","Group2", "Group2", "Group2", "Group2", "Group2", "Group2")
year = c("Year1", "Year2", "Year3", "Year1", "Year2", "Year3", "Year1", "Year2", "Year3", "Year1", "Year2", "Year3")
gender = c("Male", "Male", "Male", "Female", "Female", "Female", "Male", "Male", "Male", "Female", "Female", "Female")
count = c(15, 16, 20, 12, 13, 13, 21, 24, 25, 27, 23, 30)
data = as.data.frame(cbind(group, year, gender, as.integer(count)))
现在,在使用 geom_line 时这样做非常简单:
data %>%
ggplot(aes(year, count, color=gender, group=gender))+
geom_point(size=2.5)+
geom_line(size=1.5)+
facet_wrap(~group)+
geom_label(label=count)
但是,当使用 geom_col 和 position="fill",从而创建一个比例图时,这不起作用,因为标签(按照说明)是“计数”值。
data %>%
ggplot(aes(year, count, fill=gender))+
geom_col(position="fill")+
facet_wrap(~group)+
geom_label(label=count)
我的问题是,由于 ggplot 能够生成比例以创建 geom_col-position="fill" 样式图,有没有办法让我“访问”这些比例,然后用它们来标记我的图?
任何帮助将不胜感激。
谢谢你。