I have a plot with variables A (bars) and B (line) where legend is not showing. I have a couple of questions I'd like a hand with please:
- Legend is not showing.
Location (x-axis) is only showing 3 of the 7
My data:
)
Location <- c(1,2,3,4,5,6,7)
A <- c(0.81, 0.94, 2.31, 12.2, 11.52, 4.7, 10.13)
B <- c(3304, 97025, 187012, 25962, 383875, 96233, 227291)
df = data.frame(Location, A, B)
My code:
ggplot(df) +
geom_col(aes(Location, A), color = "black", fill = "tan1") +
geom_line(aes(Location, B/40000), size = 1.5, color="black") +
scale_y_continuous(sec.axis = sec_axis(~.*40000))
Trying to add the legend:
+ theme(legend.position = c(0.8, 0.2))+
scale_fill_manual(name = "", values = c("A" = "grey")) +
scale_color_manual(name = "", values = c("B" = "black")) +
theme_bw()