我知道有不同的方法可以将形状和颜色分配给绘图中的不同点组。这是我取得成功的方式,除了现在我的数据用row.names格式化。数据如下:
row.names Acidobacteria Actinobacteria
1 Feb Fort Falls 258 232
2 Feb Fort Falls rep serum bottle 18 60
3 Feb Fort Falls serum bottle 88 68
4 Feb Tryptone Fort Falls 34 0
5 Feb Grass Fort Falls 1032 341
6 Feb Tree Fort Falls 121 730
7 July Fort Falls 31 271
8 July Fort Falls serum bottle 254 67
9 July Tryptone Fort Falls 337 50
...等
我的问题是:如何让下面的代码与row.names一起使用?当我这样做的时候 ATTR(Brannen.diversity “row.names”) 这会显示行名称。但我无法通过格式化代码的方式获得点的形状和颜色。
代码:
# vector holding the colors
cols <- c("red", "red","red","red","red","red","blue","blue","blue","blue","blue","red","red","red","red","red","blue","blue","blue","blue","blue")
shape <- c(18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,17,17,17,17,17)
summary(shape)
# empty plot
plot(Brannen.ord, type = "n",axes=FALSE,xlab=" ",ylab=" ")
# Add points colored by Environmental Variable Management
points(Brannen.ord, col = cols[attr(Brannen.diversity,"row.names")], pch = shape[attr(Brannen.diversity,"row.names")])
text(Brannen.ord, col = "black", dis = "sp",cex=0.8)
plot(Brannen.ord.fac,p.max=0.05, cex.lab=4, cex.axis=4, cex.main=4, cex.sub=4)
# add legend
legend("bottomright",legend=levels(attr(Brannen.diversity,"row.names")), col=cols, pch = shape,cex=0.9,inset=0.1,bty="n",y.intersp=0.5,x.intersp=0.8,pt.cex=1.1)
谢谢!