I'd like to add two scales to a legend: one from a data frame and using "aes" and a second one from another data frame and "manual". I've marked in the code what I think should be modified. Thanks!
Load packages
library(tidyverse) library(RColorBrewer)
Create fake data
dd <- data.frame(Year = rep(2005:2021, 2), Balance = c(rep("Output", 17), rep("Input", 17)), Total = c(runif(17, min = 100, max = 200), runif(17, min = -99, max = -10))) drs <- filter(dd, Year %in% c(2005, 2010, 2015, 2020)) %>% arrange(Year, Balance) %>% group_by(Year) %>% mutate(diff = cumsum(Total)) %>% ungroup()
Build plot I NEED TO INCLUDE THE DOTTED LINE IN THE LEGEND
ggplot() + geom_bar(data = dd, stat = "identity", aes(x = Year, y = Total, fill = Balance)) + geom_line(data = filter(drs, Balance == "Output"), aes(x = Year, y = diff), size = 1) + geom_point(data = filter(drs, Balance == "Output"), aes(x = Year, y = diff), size = 2) + scale_fill_brewer(name = "", palette = "Blues") + scale_size_manual(name = "Balance2", values = diff) + #Here is where I have issues theme_bw() + theme(text = element_text(size = 21))