我有一个情节(下面),我试图控制传说。麻烦的是,我有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)
答案 0 :(得分:2)
在评论中由joran回答。在geom_bar调用中使用了show_guide,代码如下所示
# 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"))