ggplot版本的flower图:学好几何,画图不愁
安装R包
# library(ggClusterNet) # 可以直接安装这个github包提取测试数据,或者导入ps_liu.rds,可在公众号后台输入:数据,获取
library(ggplot2)
library(ggforce)
library(phyloseq)ps = readRDS("./ps_liu.rds")
# data(ps)
map = as.data.frame(sample_data(ps))
map$Group1 <- c("A","B","C","D","E","F ")
sample_data(ps) = map
#
#---花瓣调整宽度,标签调整位置
p <- ggflower(ps = ps,
rep = 3,
group = "Group1",
start = 1, # 风车效果
m1 = 2, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 0.3, # 花瓣胖瘦
b = 0.3, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow",
b.cir = 0.8,# 圆中心圆大小
a.cir = 0.8
)
p2 <- p + scale_fill_brewer(palette = "Paired")
p2
#---调整花瓣形状
p <- ggflower(ps = ps,
rep = 3,
group = "Group1",
start = 1, # 风车效果
m1 = 1, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 0.3, # 花瓣胖瘦
b = 1, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow"
)
p3 <- p + scale_fill_brewer(palette = "Paired")
p3
#---调整花瓣形状
p <- ggflower(ps = ps,
rep = 3,
group = "Group1",
start = 1, # 风车效果
m1 = 5, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 0.2, # 花瓣胖瘦
b = 1, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow"
)
p4 <- p + scale_fill_brewer(palette = "Paired")
p4
#---调整花瓣形状
p5 <- ggflower(ps = ps,
rep = 3,
group = "Group1",
start = 1, # 风车效果
m1 = 2, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 0.2, # 花瓣胖瘦
b = 1, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow"
)
p5
# #---调整花瓣效果
p <- ggflower(ps = ps,
rep = 3,
group = "Group1",
start = 30, # 风车效果
m1 = 2, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 0.2, # 花瓣胖瘦
b = 1, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow"
)
p1 <- p + scale_fill_brewer(palette = "Paired")
p1
#---花瓣调整宽度,标签调整位置
p6 <- ggflower(ps = ps,
rep = 6,
group = "Group",
start = 1, # 风车效果
m1 = 2, # 花瓣形状,方形到圆形到棱形,数值逐渐减少。
a = 1, # 花瓣胖瘦
b = 0.3, # 花瓣距离花心的距离
lab.leaf = 1, # 花瓣标签到圆心的距离
col.cir = "yellow",
b.cir = 0.8,# 圆中心圆大小
a.cir = 0.8
)
p6
library(patchwork)
(p1+p2+p3)/(p4+p5+p6)
函数
ggflower = function(otu = NULL,tax = NULL,map = NULL,ps = NULL,
group = "Group",
rep = 6,
m1 = 2,
start = 1,
a = 0.2,
b = 1,
lab.leaf = 1,
col.cir = "yellow",
a.cir = 0.5,
b.cir = 0.5,
m1.cir = 2
){
ps = inputMicro(otu,tax,map,tree,ps,group = group)
mapping = as.data.frame(sample_data(ps))
aa = vegan_otu(ps)
otu_table = as.data.frame(t(aa))
count = aa
sub_design <- as.data.frame(sample_data(ps))
sub_design$SampleType = sub_design$Group
sample_data(ps ) = sub_design
#
pick_val_num <- rep *2/3
count[count > 0] <- 1
count2 = as.data.frame(count)
#数据分组
iris.split <- split(count2,as.factor(sub_design$Group))
#数据分组计算平均值
iris.apply <- lapply(iris.split,function(x)colSums(x[]))
# 组合结果
iris.combine <- do.call(rbind,iris.apply)
ven2 = t(iris.combine)
ven2[ven2 < pick_val_num] = 0
ven2[ven2 >=pick_val_num] = 1
ven2 = as.data.frame(ven2)
#
ven3 = as.list(ven2)
ven2 = as.data.frame(ven2)
all_num = dim(ven2[rowSums(ven2) == length(levels(sub_design$Group)),])[1]
ven2[,1] == 1
A = rep("A",length(colnames(ven2)))
B = rep(1,length(colnames(ven2)))
i = 1
for (i in 1:length(colnames(ven2))) {
B[i] = length(ven2[rowSums(ven2) == 1,][,i][ven2[rowSums(ven2) == 1,][,i] == 1])
A[i] = colnames(ven2)[i]
}
n <- length(A)
deg <- 360 / n
t = 1:n
p <- ggplot() +
# geom_point(aes(x = 5 + cos((start + deg * (t - 1)) * pi / 180) * lab.leaf, y = 5 + sin((start + deg * (t - 1)) * pi / 180) *lab.leaf)) +
ggforce::geom_ellipse(aes(x0 = 5 + cos((start + deg * (t - 1)) * pi / 180),
y0 = 5 + sin((start + deg * (t - 1)) * pi / 180),
a = a,
b = b,
angle = (n/2 +seq(0,1000,2)[1:n])/n * pi,
m1 = m1,
fill = as.factor(1:n)),show.legend = F) +
ggforce::geom_ellipse(aes(x0 = 5,y0 = 5,a = a.cir,b = b.cir,angle = 0,m1 = m1.cir),fill = col.cir) +
geom_text(aes(x = 5,y = 5,label = "OVER :20")) +
geom_text(aes(
x = 5 + cos((start + deg * (t - 1)) * pi / 180) * lab.leaf,
y = 5 + sin((start + deg * (t - 1)) * pi / 180) * lab.leaf,
label = paste(A,":",B,sep = "")),angle = 360/n*((1:n)-1) ) +
coord_fixed() + theme_void()
p
return(p)
}
根际互作生物学研究室 简介
根际互作生物学研究室是沈其荣教授土壤微生物与有机肥团队下的一个关注于根际互作的研究小组。本小组由袁军副教授带领,主要关注:1.植物和微生物互作在抗病过程中的作用;2 环境微生物大数据整合研究;3 环境代谢组及其与微生物过程研究体系开发和应用。团队在过去三年中在 isme J, Microbiome, PCE,SBB,Horticulture Research等期刊上发表了多篇文章。欢迎关注 微生信生物 公众号对本研究小组进行了解。