【发布时间】:2014-05-20 15:38:15
【问题描述】:
我有一个情节(如下),我试图控制它的图例。问题是我同时拥有geom_line(aes(linetype = season)) 和geom_bar(aes(linetype = season))。我想显示geom_line 的图例(如下图1),而不是geom_bar 的图例(如下图2)。
如果我尝试使用scale_linetype(guide = F),它会关闭两者的图例。有没有办法显示geom_line 线型而不是geom_bar 线型的图例?下面是生成图的代码。
为什么?最终,我希望条形的轮廓与线条相匹配,并带有一个很好显示的图例。如您所见,情节 2 几乎就在那里,但传说是,嗯,难以辨认
# 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)
【问题讨论】:
-
试试
show_guide = FALSE。 -
是的,就是这样。无法将此标记为 joran 已回答,因为它是评论。谢谢!
-
你自己写答案,然后你可以将它标记为已回答,并获得代表。