I am having trouble figuring out what arguments to use in geom_text.
I have the following data frame:
head(dataset)
# A tibble: 6 x 2
diameter trip
<fct> <fct>
1 17.5 0
2 17.5 1
3 17.5 0
4 14.75 0
5 17.5 1
6 16 0
levels(dataset$diameter)
[1] "14.75" "16" "16.5" "17.5"
levels(dataset$trip)
[1] "0" "1"
I call ggplot and it returns the following graphic.
image before labeling:
dataset %>%
ggplot(aes(x = diameter,
fill = trip)) +
geom_bar(position = 'fill') +
ylab("relative frequencies")
I would like to know how to add labels that show the count of samples within each diameter, separated by trip. Something like this:
image I want to build:
I tried a lot finding it on google, without success.
I saw some people showing this post as a duplicate of the post below. Isn't there a way, with the code I have, to just add a geom_text and get what I want? It isn't exactly the same problem since his label values are from the same type shown in his y axis, while in my case, the y axis just show percentages and I want the labels to show counts.