R語言之視覺化①①熱圖繪製heatmap
目錄
R語言之視覺化①誤差棒
R語言之視覺化②點圖
R語言之視覺化③點圖續
R語言之視覺化④點韋恩圖upsetR
R語言之視覺化⑤R圖形系統
R語言之視覺化⑥R圖形系統續
R語言之視覺化⑦easyGgplot2散點圖
R語言之視覺化⑧easyGgplot2散點圖續
R語言之視覺化⑨火山圖
R語言之視覺化⑩座標系統
R語言之視覺化①①熱圖繪製heatmap
======================================
R.package
- heatmap():用於繪製簡單熱圖的函式
- heatmap.2():繪製增強熱圖的函式
- d3heatmap:用於繪製互動式熱圖的R包
- ComplexHeatmap:用於繪製、註釋和排列複雜熱圖的R&bioconductor包(非常適用於基因組資料分析)
首先使用ggplot2畫簡單熱圖
data <- as.data.frame(matrix(rnorm(9*10),9,10)) rownames(data) <- paste("Gene", 1:9, sep="_") colnames(data) <- paste("sample", 1:10, sep="_") library(reshape2) library(ggplot2) data$ID <- rownames(data) data_m <- melt(data, id.vars=c("ID")) View(data_m)
- data為9行10列的標準正太分佈資料。
- 使用paste對行列名簡單命名。
-
melt函式將data轉化為gene-id列,sample-variable列,以及表達值-value列。

p <- ggplot(data_m, aes(x=variable,y=ID)) + xlab("samples") +theme_classic() + theme(axis.ticks = element_blank(), axis.line = element_blank()) + theme(panel.grid.major = element_blank()) + theme(legend.key=element_blank())+ theme(axis.text.x=element_text(angle=45,hjust=1, vjust=1)) + theme(legend.position="top") + geom_tile(aes(fill=value)) + scale_fill_gradient2("Expression", low = "green", high = "red", mid = "black") p

- theme_classic() + #去掉灰快
- theme(axis.ticks = element_blank(),
axis.line = element_blank()) + #去掉邊框 - xlab('row name') +
ylab('column name') #更改行名和列名 - scale_x_discrete(labels = 1:10, breaks = 1:10) +
scale_y_discrete(labels = 1:10, breaks = 1:10) #修改行和列 - scale_fill_gradient2('legend name',
low = 'blue', high = 'red', mid = 'white') #修改圖例名字以及圖中顏色