簡體   English   中英

ggplot boxplot中的標簽圖例

[英]Labelling legend in ggplot boxplot

我有以下代碼:

legendCat<-c('Chemical','Computers & Communications','Drugs & Medical',
  'Electronic & Electrical','Mechanical','Others')
ggplot(cleaned,aes(x=CAT,y=ORIGINAL, fill=as.factor(CAT)))+geom_boxplot()+
  guides(colour=guide_legend(override.aes=list(legendCat)))

但是,圖例的標簽並不符合我定義的legendCat向量。 我怎么做?
獲得的情節: 在此處輸入圖片說明

提前致謝

圖例不需要特殊的向量。 只需使用:

ggplot(cleaned,aes(x=CAT,y=ORIGINAL, fill=as.factor(CAT))) +
  geom_boxplot() +
  scale_fill_discrete(breaks = 1:6, labels = c('Chemical','Computers & Communications','Drugs & Medical','Electronic & Electrical','Mechanical','Others'))

暫無
暫無

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

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