I looked on SO and I saw a lot of posts about the position of geom_text
values related to bars but I didnt see anything related to my question. Sorry if I missed it. I am trying to create a bar plot in ggpot2 with position="dodge"
and I am trying to put a summary value above each grouping of bars. I'm close but when I add the geom_text
label it shows a bunch of values. Ideally I'm looking to just remove all the values but one per grouping. My reproducible example is below. Thanks in advance for any help you can offer!
gather.iris <- iris %>%
gather(key=flower_att, value=measurement, -Species) %>%
mutate(sum_value=ifelse(Species=="setosa", 5, ifelse(Species=="versicolor", 7, 9)))
ggplot(data=gather.iris, aes(x=Species, y=measurement, fill=flower_att)) +
geom_bar(stat="identity", position="dodge") +
geom_text(aes(label=sum_value), vjust=-0.5, check_overlap=T)
Thanks Gregor for the quick answer. I didn't understand that I needed to chose a x and y value for the text like I would a plot. Heres a not so pretty answer to the question.
gather.iris <- iris %>% gather(key=flower_att, value=measurement, -Species) %>%
mutate(sum_value=ifelse(Species=="setosa", 5, ifelse(Species=="versicolor", 7, 9)))
ggplot(data=gather.iris, aes(x=Species, y=measurement, fill=flower_att)) +
geom_bar(stat="identity", position="dodge") +
geom_text(aes(y=as.numeric(Species), label=sum_value), vjust=-0.5, check_overlap=T)