Reputation: 451
I have a plot (below) that I am trying to control the legend for. The trouble is that I have both geom_line(aes(linetype = season))
and geom_bar(aes(linetype = season))
. I'd like to display the legend for the geom_line
(as in plot 1 below) rather than the legend for the geom_bar
(as in plot 2 below).
If I try using scale_linetype(guide = F)
, it turns off the legend for both. Is there a way to display the legend for the geom_line
linetype but not the geom_bar
linetype? Below is the code to produce the plots.
Why? Ultimately I would like the outline of the bars to match the lines, with a nicely displayed legend. As you can see plot 2 is almost there but the legend is, well, illegible
# code for plot 1
ggplot() +
geom_line(data = temp, aes(pos, res, linetype = season)) +
geom_bar(data = temp2, aes(depth, res, fill = season),
stat = "identity", position = "dodge", color = "black") +
scale_fill_manual(values = c("white", "black"), guide = F)
# code for plot 2
ggplot() +
geom_line(data = temp, aes(pos, res, linetype = season)) +
geom_bar(data = temp2, aes(depth, res, linetype = season, fill = season),
stat = "identity", position = "dodge", color = "black") +
scale_fill_manual(values = c("white", "black"), guide = F)
Upvotes: 0
Views: 176
Reputation: 451
Answered by joran below in a comment. Used show_guide in the geom_bar call, code shown below
# plot 3
ggplot() +
geom_line(data = temp, aes(pos, res, linetype = season)) +
geom_bar(data = temp2, aes(depth, res, linetype = season, fill = season),
stat = "identity", position = "dodge", color = "black",
show_guide = F) +
scale_fill_manual(values = c("white", "black"))
Upvotes: 2