从多个geom阴谋的特定几何压制传说 [英] suppress legend from specific geom in multiple geom plot
问题描述
我有一个情节(下图),我试图控制图例。麻烦的是我有 geom_line(aes(linetype = season))
和 geom_bar(aes(linetype = season))
。我想显示 geom_line
的图例(如下面的图1所示),而不是 geom_bar
(如下图2)。
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).
如果我尝试使用 scale_linetype(guide = F)
,它会关闭两者的图例。有没有办法显示 geom_line
linetype但不是 geom_bar
线型的图例?以下是生成图的代码。
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.
为什么?最终,我希望酒吧的轮廓与线条一致,并带有精美的图例。正如你可以看到情节2几乎在那里,但传说是,难以辨认
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)
推荐答案
。在geom_bar调用中使用了show_guide,代码如下
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"))
这篇关于从多个geom阴谋的特定几何压制传说的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!