r - 如何在 R 中创建 Pathway Enrichment 热图?
问题描述
我有一些数据如下:
dput(Int)
structure(list(ID = c("GO", "GO", "GO", "Kegg", "Reactome", "Reactome",
"GO", "GO", "GO", "GO", "Reactome", "GO", "Reactome", "GO", "Kegg",
"Kegg"), Description = c("regulation of developmental growth",
"cell maturation", "cell-substrate adhesion", "MAPK signaling pathway",
"MET activates PTK2 signaling", "Signaling by MET", "growth factor binding",
"canonical Wnt signaling pathway", "regulation of cellular response to growth factor stimulus",
"regulation of cell cycle G2/M phase transition", "Glycolysis",
"cell cycle DNA replication", "Signaling by EGFR", "stem cell differentiation",
"Ras signaling pathway", "Calcium signaling pathway"), GeneRatio = c("6/62",
"4/62", "26/224", "15/136", "8/144", "8/144", "13/220", "10/151",
"14/151", "10/332", "33/2605", "26/3798", "20/2605", "7/62",
"15/213", "15/213"), BgRatio = c("347/18670", "177/18670", "354/18670",
"438/10971", "30/10654", "79/10654", "137/17696", "335/18670",
"292/18670", "213/18670", "71/10654", "71/18670", "49/10654",
"257/18670", "337/10971", "288/10971"), pvalue = c(0.001010736,
0.002839063, 1.57e-13, 0.000338402, 4.17e-09, 1.06e-05, 1.64e-08,
0.000406096, 1.11e-07, 0.004942, 4.17e-05, 0.001096187, 0.008292794,
2.23e-05, 0.002389972, 0.00049388), p.adjust = c(0.031471355,
0.047398143, 4.9e-11, 0.00342914, 9.91e-08, 0.00018386, 8.97e-07,
0.034667052, 0.000278314, 0.038642228, 0.000242305, 0.011469503,
0.029134446, 0.015875363, 0.03632758, 0.015479437), qvalue = c(0.024333169,
0.036647518, 3.88e-11, 0.002920943, 8.26e-08, 0.000153301, 7.72e-07,
0.030920283, 0.000248234, 0.030524074, 0.000156277, 0.0094808,
0.018790567, 0.012274587, 0.029015103, 0.012363539), Count = c(6L,
4L, 26L, 15L, 8L, 8L, 13L, 10L, 14L, 10L, 33L, 26L, 20L, 7L,
15L, 15L), Subtypes = c("GroupA", "GroupA", "GroupB", "GroupB",
"GroupB", "GroupB", "GroupB", "GroupB", "GroupB", "GroupB", "GroupB",
"GroupB", "GroupB", "GroupC", "GroupC", "GroupC"), Cluster = c("Cluster1",
"Cluster1", "Cluster2", "Cluster2", "Cluster2", "Cluster2", "Cluster2",
"Cluster3", "Cluster3", "Cluster3", "Cluster4", "Cluster4", "Cluster4",
"Cluster1", "Cluster5", "Cluster5")), row.names = c(NA, -16L), class = "data.frame")
我用以下代码创建了一个点图:
library(ggplot2)
library(forcats)
library(dplyr)
Int2 <- Int[order(Int$Cluster, decreasing = FALSE),]
Int2$Description <- factor(Int2$Description, levels=Int2$Description[order(Int2$Cluster)])
p <- ggplot(Int2, aes(x = Count, y = Description)) +
geom_point(aes(size = Count, color = p.adjust)) +
theme_bw(base_size = 14) +
theme(axis.text=element_text(size=15, face = "bold", color = "black"),
axis.title=element_text(size=15, face = "bold", color = "black")) +
scale_colour_gradient(limits=c(0, 0.10), low="red") +
ylab(NULL)
p1 <- p + facet_grid(.~Subtypes, scale = "free") +
theme(strip.text.x = element_text(size = 15, colour = "black", face = "bold"))
但我有兴趣创建一个通路富集热图,显示 y 轴上的通路和顶部的簇,并在图的右侧显示子类型。
它应该看起来像这样:
解决方案
像这样的东西可能会让你更接近你正在寻找的东西,但我想知道像 {gt} 包这样的东西是否更容易把东西变成表格格式......
axis_text_colors <- case_when(Int2$ID == "GO" ~ "blue",
Int2$ID == "Kegg" ~ "purple",
Int2$ID == "Reactome" ~ "green")
ggplot(Int2) +
aes(x = Cluster, y = Description) +
facet_grid(Subtypes ~ ., space = "free_y", scale = "free_y") +
geom_tile(aes(fill = p.adjust)) +
# scale_fill_gradient(limits=c(0, 0.10), low="red") +
labs(
x = NULL,
y = NULL
) +
theme(
axis.text.x = element_text(angle = 90),
axis.text.y = element_text(color = axis_text_colors)
) +
NULL
推荐阅读
- tensorflow - Keras.module需要Tf版本=>2.2,但是DLL的Tf加载失败
- php - PHPUnit: How to test a class method that uses another static classes method
- xamarin.forms - 如何显示内容查看标签页的标签
- javascript - 当您将鼠标悬停在某物上时,这个弹出的东西是什么?
- java - 在 Java 中验证对 GitHub API 的 http 调用
- python - python合并和不匹配的记录也需要存在
- c# - 两种不同的类型,一种 C# 中的方法实现
- html - 无法在 html 锚标记中使用谷歌浏览器的顶级网站 url
- java - 抛出异常 - 使用 detalization:哪个单元格包含不正确的值
- php - PHP Curl复制请求