跟着Nature学作图:R语言corrplot包画热图展示相关系数

论文是

Environmental factors shaping the gut microbiome in a Dutch population

数据和代码的github主页链接

https://github.com/GRONINGEN-MICROBIOME-CENTRE/DMP

这个也是数据代码的下载链接,可以看目录结构

https://zenodo.org/record/5910709#.YmAcp4VBzic

今天的推文重复一下论文中的figure4b

image.png

首先是读取数据

plotCorMat <- read.table('health_disease_prediction/diseases_signature_correlation.txt',
                         header = T,
                         row.names = 1,
                         stringsAsFactors = F)
dim(plotCorMat)
plotCorMat[1:3,1:3]

对数据集的行名进行修改

rownames(plotCorMat) = c("1.Blood.Anemia",
                             "2.Blood.Thrombosis",
                             "3.Cancer.Any",
                             "4.Cardiovascular.Arrythmia.MedDiagnosed",
                             "5.Cardiovascular.Colesterol.high",
                             "6.Cardiovascular.Heart.Attack",
                             "7.Cardiovascular.Heart.Failure.Disorder",
                             "8.Cardiovascular.Heartrate.complains",
                             "9.Cardiovascular.Hypertension",
                             "10.Endocrine.DiabetesT2",
                             "11.Gastrointestinal.Stomach.Ulcer",
                             "12.Hepatologic.Gallstones",
                             "13.Mental.Any",
                             "14.Mental.Burn.Out",
                             "15.Mental.Depression",
                             "16.Mental.Other.anxiety",
                             "17.Mental.Panic.disorder",
                             "18.Neurological.Dizziness.Falling",
                             "19.Neurological.Mental.Fibromyalgia",
                             "20.Neurological.Migraine",
                             "21.Other.Autoimmune.Rheumatoid.Artritis",
                             "22.Other.Chronic.cystitis",
                             "23.Other.Chronic.Inflammation.Throatnose",
                             "24.Other.Chronic.Muscle.Weakness",
                             "25.Other.Fractures",
                             "26.Other.Incontinence",
                             "27.Other.Kidney.Stones",
                             "28.Other.Osteoarthritis",
                             "29.Other.Osteoporosis",
                             "30.Other.RSI",
                             "31.Pulmonary.Autoimmune.Asthma",
                             "32.Pulmonary.COPD",
                             "33.Skin.Autoimmune.Atopic.dermatitis",
                             "34.Skin.Autoimmune.Psoriasis",
                             "35.Skin.Autoimmune.Severe.acne",
                             "36.Gastrointestinal.Rome3_IBS.Any",
                             "37.None.NoDiseases"
)

对数据集的列名进行修改

colnames(plotCorMat) = 1:37

准备颜色

col1<-colorRampPalette(c( "#9B2226", "#AE2021","#BB3E03","#CA6702","#FFFFFF",
                          "#90e0ef", "#0077b6","#023e8a","#001219"))
col1(3)
col1(10)

作图代码

library(corrplot)
corrplot(as.matrix(plotCorMat),
         method = "square",
         tl.cex = 0.85,
         cl.cex = 0.85,
         col = col1(20),
         tl.col = "black")

这里 tl.cex是用来控制坐标轴文字的大小的
cl.cex是用来控制图例刻度文字大小的

cl 是 colorlabel

image.png

这个是论文中提供的代码出图,和最终论文中用到的图还是有些差别的

下面我们查看corrplot这个包的帮助文档看看能够通过修改代码改成最终论文中的图的效果

如果需要把图例放到底部,直接添加一个cl.pos = "b"的参数

corrplot(as.matrix(plotCorMat),
         method = "square",
         tl.cex = 0.4,
         cl.cex = 0.4,
         col = col1(20),
         tl.col = "black",
         cl.pos = "b")
image.png

关于如何修改图例的刻度标签暂时没有找到参数调节,出图后手动修改吧

更多关于corrplot包的内容可以参考 https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html

本期推文的示例数据和代码可以在公众号后台留言20220429获取

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

你可能感兴趣的:(跟着Nature学作图:R语言corrplot包画热图展示相关系数)