针对只有一个性状
## 整理cor—data (宽数据转化为长数据)
cor_data = moduleTraitCor %>% as.data.frame() %>%
rownames_to_column(var = "module") %>%
dplyr::select(module,cor = V1) %>%
left_join(moduleTraitPvalue %>% as.data.frame() %>%
rownames_to_column(var = "module") %>%
dplyr::select(module,pvalue = V1) ) %>%
mutate(datTrait = "sex") %>%
dplyr::select(module,datTrait,cor,pvalue)
# 添加相关性级别 "Strong Cor" "Weak Cor" “no Cor
cor_data = cor_data %>% mutate(levels = if_else(abs(cor) >= 0.5 & pvalue <= 0.05,
"Strong Cor",
if_else(
abs(cor) >= 0.3&abs(cor)< 0.5 & pvalue <= 0.05,
"Weak Cor",
"No Cor"
)))
# 添加相关性方向
cor_data = cor_data %>% mutate(direction = if_else(cor > 0 ,"postive","negative"))
# 更改列顺序
cor_data = cor_data %>% dplyr::select(2,1,3:length(cor_data))
# 改名去除ME
cor_data$module = cor_data$module %>% str_replace_all("ME","")
MEs = net$MEs
colnames(MEs) = colnames(MEs) %>% str_replace_all("ME","")
library(ggcor)
library(ggsci)
## ggcor绘制相关性连线图
cor_data$levels = cor_data$levels %>% factor(levels = c("No Cor","Weak Cor","Strong Cor"))
quickcor(MEs,type = 'upper')+
geom_square()+
ggcor::anno_link(data = cor_data,
aes(color = direction,
size = levels))+
scale_size_manual(values = c(0.1,1.5))+
scale_color_manual(values = c("#99CCFF","#F39B7FFF"))+
scale_fill_gsea()
针对多个性状
## 绘制相关性连接图
#######
## 整理cor—data (宽数据转化为长数据)
cor_data = moduleTraitCor %>% as.data.frame() %>%
pivot_longer(2:length(moduleTraitCor),names_to = "datTrait",values_to = "cor") %>%
left_join(moduleTraitPvalue %>% as.data.frame() %>%
pivot_longer(2:length(moduleTraitCor),names_to = "datTrait",values_to = "pvalue"),
by = join_by(module, datTrait))
# 计算(padj BH法)
# cor_data = cor_data %>% filter(datTrait %in% c("transplant_time","K_time","k_time_rate")) %>%
# mutate(padj = p.adjust(pvalue,method = "BH")) %>% bind_rows(
# cor_data %>% filter(datTrait %in% c("site","phemo")) %>%
# mutate(padj = p.adjust(pvalue,method = "BH"))
# )
# 添加相关性级别 "Strong Cor" "Weak Cor" “no Cor
cor_data = cor_data %>% mutate(levels = if_else(abs(cor) >= 0.7 & pvalue <= 0.05,
"Strong Cor",
if_else(
abs(cor) >= 0.3&abs(cor)< 0.7 & pvalue <= 0.05,
"Weak Cor",
"No Cor"
)))
# 添加相关性方向
cor_data = cor_data %>% mutate(direction = if_else(cor > 0 ,"postive","negative"))
# 更改列顺序
cor_data = cor_data %>% dplyr::select(2,1,3:length(cor_data))
# 改名去除ME
cor_data$module = cor_data$module %>% str_replace_all("ME","")
MEs = net$MEs
colnames(MEs) = colnames(MEs) %>% str_replace_all("ME","")
## ggcor绘制相关性连线图
cor_data$levels = cor_data$levels %>% factor(levels = c("No Cor","Weak Cor","Strong Cor"))
quickcor(MEs,type = 'upper')+
geom_square()+
ggcor::anno_link(data = cor_data,
aes(color = direction,
size = levels))+
scale_size_manual(values = c(0.1,0.2,1.8))+
scale_color_manual(values = c("#99CCFF","#F39B7FFF"))+
scale_fill_gsea()
#######