R包:ggcor的相关性图

安装ggcor包

原作者已经删除了该R包的链接,需要自己上网搜索下载并安装该包。本地安装包。

PS: 为了方便大家,暂时把安装包放在百度云盘,尽量下载保存到本地,后期我可能会删除该包

链接:https://pan.baidu.com/s/10zk5El3kooeHuPsz2qul-A 
提取码:3zly

加载包

library(vegan)
library(ggcor)
library(tidyverse)

Correlation plot

set_scale()
quickcor(mtcars) + geom_square()
quickcor(mtcars, type = "upper") + geom_circle2()
quickcor(mtcars, cor.test = TRUE) +
  geom_square(data = get_data(type = "lower", show.diag = FALSE)) +
  geom_mark(data = get_data(type = "upper", show.diag = FALSE), size = 2.5) +
  geom_abline(slope = -1, intercept = 12)

Mantel test plot

data(varechem)
data(varespec)
mantel <- mantel_test(varespec, varechem,
                      spec.select = list(Spec01 = 1:7,
                                         Spec02 = 8:18,
                                         Spec03 = 19:37,
                                         Spec04 = 38:44)) %>% 
  mutate(rd = cut(r, breaks = c(-Inf, 0.2, 0.4, Inf),
                  labels = c("< 0.2", "0.2 - 0.4", ">= 0.4")),
         pd = cut(p.value, breaks = c(-Inf, 0.01, 0.05, Inf),
                  labels = c("< 0.01", "0.01 - 0.05", ">= 0.05")))

quickcor(varechem, type = "upper") +
  geom_square() +
  anno_link(aes(colour = pd, size = rd), data = mantel) +
  scale_size_manual(values = c(0.5, 1, 2))+
  guides(size = guide_legend(title = "Mantel's r",
                             order = 2),
         colour = guide_legend(title = "Mantel's p", 
                               order = 1),
         fill = guide_colorbar(title = "Pearson's r", order = 3))

Circular heatmap

rand_correlate(100, 8) %>% ## require ambient packages
  quickcor(circular = TRUE, cluster = TRUE, open = 45) +
  geom_colour(colour = "white", size = 0.125) +
  anno_row_tree() +
  anno_col_tree() +
  set_p_xaxis() +
  set_p_yaxis()

参考

  1. ggcor绘制相关性热图

  2. ggcor

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容