您好,登錄后才能下訂單哦!
本篇文章為大家展示了R語言ggplot2繪制熱圖展示GO富集分析結果的是怎樣的,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
這個圖的實現辦法有很多,今天的推文介紹一下使用R語言的ggplot2實現上圖的代碼。
構造數據用到的代碼
x<-seq(0,1,by=0.001)
set.seed(1234)
x1<-sample(x,240)
mymatrix<-matrix(x1,ncol=6)
head(mymatrix)
colnames(mymatrix)<-paste0("gene",1:6)
rownames(mymatrix)<-paste0("GO:000",1:40," ",
sample(LETTERS[1:26],40,replace = T))
write.csv(mymatrix,file = "GO_qvalue.csv",quote=F,row.names = T)
dfclass<-data.frame(x="class",
y=rownames(mymatrix),
group=c(rep("Biological Process",25),
rep("Cellular Component",5),
rep("Molecular Function",10)))
write.csv(dfclass,file = "class.csv",quote=F,row.names = F)
大家可以自己運行代碼得到示例數據,或者直接在文末留言
數據部分截圖如下
最基本的熱圖代碼
df1<-read.csv("GO_qvalue.csv",header = T,row.names = 1)
df1$GO_term<-rownames(df1)
df1.1<-reshape2::melt(df1,var.id="GO_term")
head(df1.1)
df1.1$GO_term<-factor(df1.1$GO_term,
levels = row.names(df1))
library(ggplot2)
ggplot(df1.1,aes(x=variable,y=GO_term))+
geom_tile(aes(fill=value))
ggplot(df1.1,aes(x=variable,y=GO_term))+
geom_tile(aes(fill=value),color="grey")+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0),
position = "right")+
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(angle = 90,hjust=1,vjust = 0.5))+
scale_fill_gradient(low="red",high="green")
說實話這個紅綠配色的熱圖我真欣賞不來,我們換一個配色吧還是
ggplot(df1.1,aes(x=variable,y=GO_term))+
geom_tile(aes(fill=value),color="grey")+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0),
position = "right")+
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(angle = 90,hjust=1,vjust = 0.5))+
scale_fill_viridis_c()
這個顏色看起來還挺舒服的
df2<-read.csv("class.csv",header = T)
head(df2)
df2$y<-factor(df2$y,
levels = rownames(df1))
ggplot(df2,aes(x=x,y=y))+
geom_tile(aes(fill=group),color="grey")+
theme(panel.background = element_blank(),
axis.title = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_text(angle=90,hjust=1,vjust=0.5))+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0))+
scale_fill_manual(name="class",
values = c("#619cff","#00ba38","#f8766d"))
library(ggplot2)
p1<-ggplot(df1.1,aes(x=variable,y=GO_term))+
geom_tile(aes(fill=value),color="grey")+
scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0),
position = "right")+
theme(panel.background = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
axis.text.x = element_text(angle = 90,hjust=1,vjust = 0.5))+
scale_fill_viridis_c(name="Q-value")
p2<-ggplot(df2,aes(x=x,y=y))+
geom_tile(aes(fill=group),color="grey")+
theme(panel.background = element_blank(),
axis.title = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_text(angle=90,hjust=1,vjust=0.5))+
#scale_x_discrete(expand = c(0,0))+
scale_y_discrete(expand = c(0,0))+
scale_fill_manual(name="class",
values = c("#619cff","#00ba38","#f8766d"))
library(aplot)
p1%>%
insert_left(p2,0.1)
最終的結果如下
上述內容就是R語言ggplot2繪制熱圖展示GO富集分析結果的是怎樣的,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。