我有以下数据,并希望像这样创建一个分组条形图:
data<-as.data.frame(c("a","b","c","a","b","c"))
colnames(data)<-"Y"
data$X<-c("x","x","x","y","y","y")
data$Z<-c(1,2,3,1,2,3)
ggplot(data, aes(x=X, y=Z, fill=Y) +
geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) +
scale_fill_manual(values=c("red","red","red","blue","blue","blue"))
在代码的最后一行中,我希望更改条形的颜色 - 我希望组“x”的所有条都涂成红色,组“y”的条都涂成蓝色。但是,如下面的结果所示,我无法使用scale_fill_manual
.