here is my dataframe
tata3 <- data.frame( stringsAsFactors = TRUE, Subtype = c("OPC", "Hypopharynx", "Larynx"),
alive = c(88, 22, 100), dead = c(12, 55, 17), uncertain = c(10, 2, 2), total = c(186,46,202))
I enter the following code to generate a nice graph.
ggplot (data = tata3, aes(x=Subtype, y =total, fill=Subtype)) +
geom_col() + scale_fill_manual(values = c("Red", "Green", "Blue"))
what I want is this..
- The Y axis maintained as it is (showing the total values as they are)
- The value in % displayed on top of the graph (in this case OPC will be "42.8%")...with the option to also display the actual value (in the case of OPC "186") besides the percentage.
I've tried various permutations of geom_text including stat_count...but I think I'm failing to specify exactly what Rstudio needs to use to calculate the percentage from. E.g. the code below gives a massive error.
ggplot (data = tata3, aes(x=Subtype, y =total, fill=Subtype)) + geom_col() + scale_fill_manual(values = c("Red", "Green", "Blue")) + geom_text (aes(label=after_stat('prop*100'), group=1),stat='total',nudge_y=0.125,va='bottom', format_string='{:.1f}%')
Can someone please help. Many thanks