I have the following code which prints a bar plot that shows the cumulated installed capacity for wind energy and pv in Germany from 2000 until 2019. I was wondering if there is a way to add a line to the plot that shows the difference per period for each technology?
library(ggplot2)
wind <- c(6095, 8754, 12001, 14609, 16629,
18428, 20621, 22247, 23903, 25777,
27190, 29060, 30989, 33729, 38115,
41651, 45910, 50777, 52931, 53912)
pv <- c(110, 180, 324, 435, 1105, 2056, 2899,
4170, 5120, 10566, 18006, 25916, 34077,
36710, 37900, 39224, 40716, 42492, 45452, 49395)
year <- c(2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011,
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019)
df <- data.frame(year, wind, pv) %>%
pivot_longer(cols = 2:3)
p1 <- ggplot(df, aes(fill=name, y=value, x=year)) +
geom_bar(position="stack", stat = "identity") +
ylab("MW") + theme(axis.text.x = element_text(angle = 45, vjust = .6)) +
scale_fill_discrete(name = "Technology", labels = c("wind", "pv"))
p1

