在ggplot中使用guide_legend和geom_bar

时间:2016-08-04 11:07:15

标签: r geom-bar

有没有让geom_legend与geom_bar一起工作?我希望在我的传奇中有太多的线条。它适用于geom_line,但不适用于geom_bar图表。

我在这里使用时效果很好:

ggplot(diamonds, aes(x,y)) + 
      geom_point(aes(colour = z))+
      guides(col = guide_legend(ncol = 2))

它不起作用的代码如下:

ggplot(diamonds, aes(clarity, fill=cut)) + 
       geom_bar()+
       guides(col = guide_legend(ncol = 2))

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在最后一行将col更改为fill。颜色不是映射美学,填充是。

相关问题