我的条形图中有颜色问题。我有一个4x4矩阵“allmat”:
A B C D
L 0.10260 0.0215700 3.017e-01 0.06917
F 0.09840 0.0206900 2.009e-01 0.11450
M 0.14100 0.0065630 3.252e-01 0.35050
G 0.02121 0.0006811 5.454e-06 0.13810
要在一个图表中绘制列,我使用:
mp<-barplot(allmat,beside=T,axisnames=F,col=c("red","black","green","blue"))
mtext(1,at=mp,text=c("L","F","M","G"),line=0,cex=0.5)
mtext(1,at=colMeans(mp),text=c("A","B","C","D"),line=2)
我得到的是每一行都有相同的颜色,但我希望列的颜色相同。我该怎么做?
最佳,
欧根
答案 0 :(得分:4)
您实际上可以单独为每个条形指定颜色。
mp<-barplot(allmat,beside=T,axisnames=F,
col=c(rep("red",4),rep("black",4),rep("green",4),rep("blue",4)))