从原图我们很容易发现,主要有三部分:右上角是类似于corrplot包中的上三角相关系数图;下三角是一组点之间的连接线(作者用了弧线,直线也能达到同样的效果);剩余部分主要是图例等其它辅助绘图元素。
R语言才是最好的拼图软件,只要你愿意花时间。时间来到这个历史节点上,就是这个图已经有人做出来了,而且,以你残缺的R基础也已经重新在自己电脑上重新绘制出来(尽管是在单身的学长的帮助下)。那么,这个图里面的点线面及其颜色各代表什么实际的生物学或者社会学的意义,它在讲诉一个怎样的故事?花瓶型还是内涵型?
核心函数:segments。
图例框框
这张图不过是相关系数的展现形式的一种创新,炫的地方在与下面的几条线。那么,我们不禁要问,这种形式的图和pheatmap按照p值标签的图有什么本质的区别吗?
R语言之照猫画虎2
1. R语言自带函数cor(data, method=" ")可以快速计算出相关系数 ,数据类型:data.frame
如data.frame为:zz, 绘图如下:
a. single protein:线性回归画法
1. ggplot(zz,aes(x=a, y=HDL))+
geom_point(alpha=1,colour="#FFA54F")+
geom_smooth(method = lm,colour="#8B658B")+
#scale_color_brewer(palette = "Set1")+
theme_bw()+
labs(x="Ferritin",y="HDL.C",title="Pearson’s correlation test of ferritin and HDL.C")+
annotate("text", x = 1000, y = 2.5, label = "r = -0.51",colour="black",size=4)
2. library(ggstatsplot)
ggscatterstats(data = alldata,
y = TRANSFUSION.UNIT,
x = NPTXR,
centrality.para = "mean", #"mean" or "median"
margins = "both",
xfill = "#D8BFD8",
yfill = "#EEDD82",
#line.size= ,
line.color="#8B6969",
point.color="#2F4F4F",
marginal.size=4,
marginal.type = "density", # "histogram", "boxplot", "density", "violin", "densigram")
title = "Relationship between TRANSFUSION.UNIT and NPTXR")
b. ggcorrplot, 全部蛋白 global correlation map 画法
ggcorrplot(cor(alldata))
2. summary(lm(y~x),method=" ") %>%.[["coefficients"]] 正规线性回归
(其实就是:a<-lm(y~x1+x2+...,data)
plot(summary(lm(y~x),method=" ")) #绘图
3. ggcor部分数据绘图: 数据类型为data.frame,纵坐标为各指标or各蛋白,行为观测值。
data <- fortify_cor(alldata[,10:11],alldata,cluster.type = "col")
ggcor<-ggcor(data,label_size=0.5) +
geom_colour()+
theme(axis.text.x = element_text(colour = "black",size = 4.7),
axis.text.y=element_text(size=5.5),
axis.ticks=element_blank())+
geom_num(aes(num=r),colour="black",size=1.5)
4. corrr包画法
datasets::mtcars %>%
correlate() %>%
focus(-cyl, -vs, mirror = TRUE) %>%
rearrange() %>%
network_plot(min_cor = .2)