我有以下代码:
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向量来实现的。我怎么做?
获得的情节:
提前致谢
答案 0 :(得分:0)
图例中不需要特殊的矢量。只需使用:
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'))