I am trying to make a bar plot + line plot. My data look like this:
Year= c(1951, 1952, 1953, 1954, 1955, 1956)
Difference = c(-1, -2, 3, 1, -2, 1)
Total = c(-0.8, -0.7, 1.1, 2.3, 1.7, 1.6)
pos = c(TRUE, TRUE, FALSE, FALSE, TRUE, FALSE)
I use pos to separate negative and positive values to plot bars in different colors. But the problem is, that pos should be applied only for Difference. The Total needs to be plotted as a line, but when I do this, the second line appears.
My code is:
ggplot(df, aes(x = Year, y = Difference, fill = pos)) + geom_col(position = "identity", colour = "black", size = 0.25) + scale_fill_manual(values = c("#CCEEFF", "#FFDDDD"), guide = "none")+ geom_line(mapping = aes(x=Year, y=Total),size=1,fill='grey',fatten = 1, guide = "none")
How to get rid of the unnecessary line? Thank you!


fill = posingeom_col(aes(...))instead of the global plot?