[英]How to plot a matrix with numbers in the matrix colored using ggplot2 or other ways in R? The numbers are the snp count from vcf file
嘗試這個:
library(dplyr)
library(ggplot2)
df <- data.frame( Gene= c("ACC", "XTG", "CFG"),
BRCA= c(23,12,45),
THYM= c(21,13,4),
TGHJ= c(7,9,8))
mdf <- gather(df, -Gene, key="key", value="count")
ggplot(mdf, aes(x=Gene, y=key, fill=count, label=count))+
geom_tile()+
geom_text()+
scale_fill_gradient(high="red2", low="white")
由於您的數據似乎是生物學的,因此我建議使用熱圖函數,該函數在一些出版物中也使用過。
library(gplots)
heatmap.2(as.matrix(df[-1]),
scale = "none",
trace = "none",
labRow = as.character(df$Gene),
cexRow=0.9, cexCol = 0.9,
cellnote=as.matrix(df[-1]),
notecol="black",
notecex = 2)
還嘗試通過scale = c("none","row", "column")
或通過dendrogram = c("both","row","column","none")
其他排序來縮放數據。 您可以嘗試更改顏色col= colorpanel(10, low = "white", mid = "yellow", high = "red")
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.