2016-08-04 215 views
-1

是否有任何使geom_legend與geom_bar一起工作的方法?我想在我的傳奇中擁有太多線條。它適用於geom_line,但不適用於geom_bar圖表。在ggplot中使用guide_legend和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)) 

感謝您的幫助。

回答

0

在最後一行中將col更改爲fill。顏色不是映射的美學,填充是。