R堆积的条形图标签不匹配

时间:2017-07-25 16:31:27

标签: r legend vegan stackedbarseries

我有9种不同样品中各种门的相对丰度(%)的分子测序数据,我试图将其绘制为颜色编码的条形图(其中每个门对应不同的颜色)。在excel上足够简单,但对于R上的一个完整的新手,我正在努力奋斗。我的数据采用excel格式(格式化为制表符),其中第一行是标签(例如样本名称) - 绘制时,条形标签放错位置,不匹配,R绘制我的excel文件的第一行(名称)作为单独的值(附图片)。到目前为止我所拥有的是:

attach(data) 
data.1<-as.matrix(data)
par(mfrow=c(1,1))
barplot(data.1, col=c("aquamarine3","azure2","blue2","brown3","cadetblue3","deepskyblue3","firebrick3","gold3","darkorange3","darkorchid3","darkseagreen","darkslateblue","darkviolet","deeppink4"), main=".", xlab="Unit/Treatment", ylab="% Relative abundance")
detach(data)

legend("topright", inset=c(-0.2,0),
       legend = c("Unassigned", "Acidobacteria","Actinobacteria","Bacteroidetes","Chlorobi","Chloroflexi","Firmicutes","Gemmatimonadetes","Planctomycetes","Proteobacteria","Verrucromicrobia","Euryarchaeota","Crenarchaeota","Parvarchaeota"), 
       fill = c("aquamarine3","azure2","blue2","brown3","cadetblue3","deepskyblue3","firebrick3","gold3","darkorange3","darkorchid3","darkseagreen","darkslateblue","darkviolet","deeppink4"))
par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)
layout(mat, widths = rep.int(1, ncol(mat)),
       heights = rep.int(1, nrow(mat)), respect = FALSE)

结果,我得到了这个:

条形图尝试,其中R将我的样本名称绘制为x_1,从而移动其他标签。另外,我的传说涵盖了我的大部分条形图,我似乎无法调整它。

非常感谢 - 任何有助于让条形图看起来都很体面的帮助都会受到高度赞赏。

0 个答案:

没有答案