I am trying to use geom_text to label a faceted geom_col plot where the position="fill".
This is a simplified version of the data I am using:
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)))
Now, doing this when using geom_line is very straight forward:
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)
However, when using geom_col and position="fill", thereby creating a proportional plot, this doesn't work, as the labels (as instructed) are the 'count' values.
data %>%
ggplot(aes(year, count, fill=gender))+
geom_col(position="fill")+
facet_wrap(~group)+
geom_label(label=count)
My question is, as ggplot has the ability to generate proportions in order to create a geom_col-position="fill" style plot, is there a way for me to 'access' these proportions and then use them to label my plot?
Any help would be greatly appreciated.
Thank you.