簡體   English   中英

ggplot2:如何在箱線圖中調整填充顏色(並更改圖例文本)?

[英]ggplot2: How to adjust fill colour in a boxplot (and change legend text)?

我怎樣才能:

  1. 在下面的箱子圖中設置填充顏色? 我嘗試了“顏色”這個論點,但那次失敗了。
  2. 將圖例文本從“0”,“1”更改為其他內容?

     require(ggplot2) ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot(aes(fill=factor(vs), colour=c("grey50", "white"))) 

您需要調整填充美感,而不是顏色美感。 您可以通過調整比例來處理您的兩個問題(以及更多):

ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(vs))) + 
  geom_boxplot() +
  scale_fill_manual(name = "This is my title", values = c("pink", "green")
                    , labels = c("0" = "Foo", "1" = "Bar"))

對於GGPLOT2網站幫助頁面scale_manual是滿不錯的例子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM