I have this small subset of a larger data frame:
years <- c(2015, 2019, 2020, 2021, 2021, 2022)
Points <- c(7, 26, 9, 18, 28, 12)
Design <- c("Standard 2019", "Standard 2019", "Standard 2019", "Standard 2019", "LCT 2021", "LCT 2021")
PointSummary <- data.frame(years, Points, Design)
I want to create a stacked bar plot showing the number of points sampled in each year and in each design (Standard 2019 or LCT 2021). It should look like this:
I can change the themes and such myself, but I need help adding labels to the stacked bars. Here is my current code, calling geom_text
:
library(ggplot2)
ggplot(data = PointSummary, aes(x = years, y = Points, fill = Design)) +
geom_bar() +
geom_text(position = position_stack(vjust = 1.6), color = "white", size = 6)