我有多个数据库,来自13个地点的每一个,有90个不同物种的平均丰度数据,按比例缩小如下:
site1<-data.frame(species = LETTERS[1:26], abundance = sample(x = 1:10, rep = TRUE, size = 26))
site2<-data.frame(species = LETTERS[1:26], abundance = sample(x = 1:10, rep = TRUE, size = 26))
site3<-data.frame(species = LETTERS[1:26], abundance = sample(x = 1:10, rep = TRUE, size = 26))
site4<-data.frame(species = LETTERS[1:26], abundance = sample(x = 1:10, rep = TRUE, size = 26))
我想要实现的是一个条形图的网格,每个地点最丰富的10个物种按降序排列.我使用用途:
site1plot<-ggplot(head(site1,10), aes(x=reorder(species, - abundance), y=abundance, fill = species)) + geom_bar(stat="identity")
site2plot<-ggplot(head(site2,10), aes(x=reorder(species, - abundance), y=abundance, fill = species)) + geom_bar(stat="identity")
site3plot<-ggplot(head(site3,10), aes(x=reorder(species, - abundance), y=abundance, fill = species)) + geom_bar(stat="identity")
site4plot<-ggplot(head(site4,10), aes(x=reorder(species, - abundance), y=abundance, fill = species)) + geom_bar(stat="identity")
ggarrange(site1plot,site2plot,site3plot,site4plot, common.legend = TRUE, legend = "bottom")
我的问题是,因为不同的网站都有不同的前10个物种,图例不适合所有的,即使我可以使它包括所有的物种,我需要的图表都有不同的 colored颜色 ,每个物种取决于顺序.如果我不做共同的图例,图表变得超级混乱,因为我有13个站点,并有他们网格与图例下面的每个是有点多.希望有个简单的解决办法?任何帮助非常感谢!
我的问题是,前10个物种在不同的地点不同,