这是获得你想要的东西的方法:
# put your data.frame in a list l_all <- list(data1, data2, data3, data4) # add an index (actually, it's not necessary but may be useful to retrieve the data later l_all <- lapply(seq(l_all), function(x){l_all[[x]] <- cbind(l_all[[x]], ind=x)}) # bind the data all_tab <- do.call(rbind, l_all) # then draw your plot, for example for "Glutamic acid (3TMS)" barplot(all_tab[row.names(all_tab) %in% "Glutamic acid (3TMS)", 1:10], beside=TRUE, col=c("blue", "orange", "grey", "yellow"), main="Glutamic acid (3TMS)", las=1)
编辑
要一次性获取所有图表,您可以:
par(mfrow=c(5, 1)) # for example for(name in unique(row.names(all_tab))){ barplot(all_tab[row.names(all_tab) %in% name, 1:10], beside=TRUE, col=c("blue", "orange", "grey", "yellow"), main=name, las=1) par(page=FALSE) }
EDIT2
如果您希望导出为pdf(每个绘图一页),这是一种方法(您必须填写"空白"):
pdf("path_to_file.pdf", s in inches, 7 is the default for both values for(name in unique(row.names(all_tab))){ barplot(all_tab[row.names(all_tab) %in% name, 1:10], beside=TRUE, col=c("blue", "orange", "grey", "yellow"), main=name, las=1) } dev.off()