1.热图制作及ggplot2、pheatmap、reshape2包的使用
library(ggplot2)
library(pheatmap)
library(reshape2)
csvpath <- file.choose()
csvpath
df <- read.csv(csvpath,header = T,row.names =1)
df
p <- pheatmap(log((df+200),2), show_rownames = F, cellwidth =5, cellheight=2,cluster_cols = T,
cutree_col =2 ,gaps_col = c(2,4,6), angle_col = 90,fontsize = 5)
row_cluster = cutree(p$tree_row, k=1)
pheatmap(log((df+1),2),cellwidth=15, cellheight=10,cluster_cols=F,cluster_rows=T)
结果展示:
2.环状热图制作
2.1ggcor包的下载及使用(一定要下载ggcor包,另外ggcor包和ggcorplot可不一样哦)
devtools::install_git("https://gitee.com/dr_yingli/ggcor")
调用程序包及基础代码
library(ggcor)
library(ambient)
csvpath <- file.choose()
csvpath
df <- read.csv(csvpath,header = T,row.names =1)
df
rand_correlate(38,20) %>%
quickcor(circular = TRUE, cluster = TRUE, open=45) +
geom_colour(colour= "pink", size = 0.38) +
anno_row_tree() +
anno_col_tree() +
set_p_yaxis()
结果展示:
(小白如果不知道函数各个参数代表什么的话,一开始可以更改部分参数,试试,绝对有用的哈!)
3.组合相关热图制作
ibrary(ggplot2)
library(patchwork)
csvpath <- file.choose()
csvpath
df <- read.csv(csvpath,header = T,row.names =1)
df
A <- quickcor(df) + geom_color()
B <- quickcor(df, type = "upper") + geom_circle2()
C <- quickcor(df, type = "lower") + geom_ellipse2()
D <- quickcor(df, cluster = TRUE) + geom_square()
E <- quickcor(df, cor.test = TRUE) + geom_confbox()
G <- quickcor(df, cor.test = TRUE) +
geom_square(data= get_data(type = "lower"))+
geom_mark(data= get_data(type = "upper")) +
geom_abline(slope = -1, intercept = 12)
(A+B+C)/(E+D+G) + plot_annotation(tag_levels = 'A')
plot(B)
A:
B:
C:
D:
E:
G:
(今天就学习这么多,觉着学习R还是挺有意思的,希望自己可以坚持下去,当然也不能舍本逐末,忘了初心,R只是为了给科研“添砖加瓦”、“锦上添花”),希望它只是一个工具!学有余力的快乐来源。