df <- data.frame(Taxon=c("A", "B", "C"),
Counts=c(0.1,0.5,0.4),
Treatment=rep("X1",3),
Effect=factor(c("A","B","A")))
df$Effect <- factor(df$Effect, levels=c("A","B"), ordered=T)
ggplot() +
geom_bar(data=df, aes(x = Treatment, y = Counts, fill = Taxon, colour=Effect),
stat="identity", position="fill", width=0.5)+
scale_fill_manual("",values=c("gold", "green","yellow"))+
scale_color_manual("",values=c("black","red"))
我想突出显示效果类型的所有“Taxon”周围带有红色边框的效果“B”。但ggplot似乎按照df$Taxon
的顺序绘制矩形,而不是我希望通过首先应用分配给df $ Effect == A的颜色,然后df $ Effect == B.同样的情况也是如此。改变df $效果的顺序。
df$Effect <- factor(df$Effect, levels=c("B","A"), ordered=T)
ggplot() +
geom_bar(data=df, aes(x = Treatment, y = Counts, fill = Taxon, colour=Effect),
stat="identity", position="fill", width=0.5)+
scale_fill_manual("",values=c("gold", "green","yellow"))+
scale_color_manual("",values=c("black","red"))
当我想在表达效果“B”的分类词周围总是有完整的红色矩形时,如何对此进行编码?