把玫瑰图大胆用起来
写在前面
玫瑰图虽然在疫情数据上有了应用,但是在我们微生物生态领域可以完好的使用,除非你解决一下两个问题:
1 如何让这个圈比较小的部分可以清楚的被标记和识别
2 我不想要一整个圈,来半个圈行不行。
好吧我就是来解决问题的。
# write.csv(a3,"./测试数据.csv")
data = read.csv("./测试数据.csv")
head(data)
## X KO WT MeanDecreaseAccuracy MeanDecreaseGini phylum
## 1 OTU_1 12.24 8.41 11.40 4.80 Gemmatimonadetes
## 2 OTU_2 12.61 8.08 10.78 6.62 Proteobacteria
## 3 OTU_3 6.90 7.31 7.74 5.84 Proteobacteria
## 4 OTU_4 6.28 5.96 6.71 1.40 Acidobacteria
## 5 OTU_5 5.86 6.03 6.57 4.02 Firmicutes
## 6 OTU_6 5.63 6.23 6.56 3.65 Proteobacteria
## class order family genus id2 iid
## 1 Gemm-1 <NA> <NA> <NA> OTU1 1
## 2 Alphaproteobacteria Sphingomonadales Sphingomonadaceae <NA> OTU2 2
## 3 Gammaproteobacteria Xanthomonadales Xanthomonadaceae <NA> OTU3 3
## 4 Acidobacteria-6 iii1-15 <NA> <NA> OTU4 4
## 5 Bacilli Bacillales Bacillaceae Bacillus OTU5 5
## 6 Gammaproteobacteria Xanthomonadales Xanthomonadaceae <NA> OTU6 6
colnames(data)[1] = "id"
library("ggplot2")
library(tidyverse)
p=ggplot(data, aes(y= MeanDecreaseAccuracy, x = reorder(id,desc(MeanDecreaseAccuracy)))) +
# geom_point(size=6,pch=20,aes(colour=phylum,fill=phylum))+
geom_bar(stat = "identity",aes(colour=phylum,fill=phylum),width = 0.3)
p
library(RColorBrewer)#调色板调用包
display.brewer.all()#调用所有这个包中的调色板mi = brewer.pal(10,"Set1")#仅仅只显示色号
mi2 = brewer.pal(10,"Set2")
mi = c(mi,mi2)
head(data)
## id KO WT MeanDecreaseAccuracy MeanDecreaseGini phylum
## 1 OTU_1 12.24 8.41 11.40 4.80 Gemmatimonadetes
## 2 OTU_2 12.61 8.08 10.78 6.62 Proteobacteria
## 3 OTU_3 6.90 7.31 7.74 5.84 Proteobacteria
## 4 OTU_4 6.28 5.96 6.71 1.40 Acidobacteria
## 5 OTU_5 5.86 6.03 6.57 4.02 Firmicutes
## 6 OTU_6 5.63 6.23 6.56 3.65 Proteobacteria
## class order family genus id2 iid
## 1 Gemm-1 <NA> <NA> <NA> OTU1 1
## 2 Alphaproteobacteria Sphingomonadales Sphingomonadaceae <NA> OTU2 2
## 3 Gammaproteobacteria Xanthomonadales Xanthomonadaceae <NA> OTU3 3
## 4 Acidobacteria-6 iii1-15 <NA> <NA> OTU4 4
## 5 Bacilli Bacillales Bacillaceae Bacillus OTU5 5
## 6 Gammaproteobacteria Xanthomonadales Xanthomonadaceae <NA> OTU6 6
# a3$iid = paste(1:length(a3$id))
library(ggplot2)
angle1 = 90 - 360 * ( as.numeric(data$iid) - 0.5) /length(data$id)
# , label =phylum
data$id = factor(data$id,levels = data$id)
p = data %>%
ggplot(aes(factor(id), MeanDecreaseAccuracy, fill = phylum, group = phylum, label =family)) +
geom_bar(stat = 'identity', position = 'dodge') +
scale_fill_manual(values = mi)+
geom_text(hjust = 0, angle = angle1, alpha = .5) +
coord_polar() +
ggtitle('') +
# ylim(c(-5,13))+
theme_void()
p
p = data %>%
ggplot(aes(factor(id), MeanDecreaseAccuracy, fill = phylum, group = phylum, label =family)) +
geom_bar(stat = 'identity', position = 'dodge') +
scale_fill_manual(values = mi)+
geom_text(hjust = 0, angle = angle1, alpha = .5) +
coord_polar() +
ggtitle('') +
ylim(c(-5,13))+
theme_void()
p
mi = brewer.pal(10,"Set1")#仅仅只显示色号
a4 = matrix(NA,nrow = dim(data)[1]/4,ncol = dim(data)[2])
dim(a4)## [1] 11 12
a4 = as.data.frame(a4)
colnames(a4) = colnames(data)
a5 = rbind(data,a4)
num = dim(data)[1] +1
head(a5)a5$iid = paste(1:length(a5$id))
a5$id = as.character(a5$id)
a5$id[num :length(a5$id)] = paste("A",(1:length(a5$id[num :length(a5$id)])),sep = "")
a5$id = factor(a5$id,levels = a5$id)
angle = 90 - 360 * ( as.numeric(a5$iid) - 0.5) /length(a5$id)
# , label =phylum
p = a5 %>%
ggplot(aes(factor(id), MeanDecreaseAccuracy, fill = phylum, group = phylum, label =family)) +
geom_bar(stat = 'identity', position = 'dodge') +
scale_fill_manual(values = mi)+
geom_text(hjust = 0, angle = angle, alpha = .5) +
coord_polar() +
ggtitle('') +
# ylim(c(-10,13))+
theme_void()
p
p = a5 %>%
ggplot(aes(factor(id), MeanDecreaseAccuracy, fill = phylum, group = phylum, label =family)) +
geom_bar(stat = 'identity', position = 'dodge') +
scale_fill_manual(values = mi)+
geom_text(hjust = 0, angle = angle, alpha = .5) +
coord_polar() +
ggtitle('') +
ylim(c(-10,13))+
theme_void()
p
如果你想交流
微生信生物群2快捷通道: