I am trying to refine a stacked bar chart and am having several issues:
- I want to extend the labelling of my y axis. At the moment the labels stop at 56,000,000 but I want a label at the top to show the total (70,000,000).
- How do I force the chart to always have the value for 'bedload' on the bottom and 'suspended' on the top rather than defaulting to the highest value on the bottom.
- Why does my geom_hline not appear on the chart? I don't get any errors it just doesn't show up. The data is simple:
Scenario 1 - Suspended = 56,000,000 Bedload = 14,000,000 Scenario 2 - Suspended = 28,000,000 Bedload = 42,000,000
My code is as follows:
plt1 <- ggplot() +
geom_bar(aes(y = Volume, x = Scenario, fill = Source),
data = SedimentLoad,
stat = "identity")+
theme_bw() +
theme_classic()+
scale_fill_manual(values = c("#CCCCCC","#666666"))+
labs(fill = "Source", x = "Scenario", y = "Volume m^3")+
theme(text=element_text(size=8, family = "Arial"))+
geom_hline(yintercept = 19000000, linetype=3)
plt1
Thankyou
For issue no 1 & 3, maybe your
Volumedata is not numeric. If not, you can mutate your data type to numeric first. For issue no 2, you can reorder the factor. Here is the sample code:Here is sample output: