绘制KEGG富集结果气泡图,并将富集结果按照category在图中分割开,请给出R语言的代码
时间: 2025-06-09 10:04:53 浏览: 17
在R语言中,可以使用`ggplot2`库来创建KEGG富集结果的气泡图,并通过`facets_wrap`或`facet_grid`对富集结果按类别分开。假设你已经有了一个包含`pathway`, `category`, `pvalue`, 和 `size`(代表重要性或统计显著性)的dataframe,例如`kegg_data`。下面是一个简单的示例代码:
```R
# 首先安装并加载所需的库
install.packages("ggplot2")
library(ggplot2)
# 假设你的数据结构如下
kegg_data <- data.frame(
pathway = c('pathway1', 'pathway2', 'pathway3', ...), # 假设这是KEGG路径
category = c('categoryA', 'categoryB', 'categoryA', 'categoryB'), # 分类
pvalue = c(0.05, 0.01, 0.03, 0.001), # P值
size = c(100, 50, 75, 20) # 泡泡大小
)
# 创建气泡图
kegg_plot <- ggplot(kegg_data, aes(x = log(pvalue), y = size, color = category, fill = category)) +
geom_point(shape = 16, alpha = 0.8, stroke = 0.5) + # 气泡形状和透明度
scale_fill_manual(values = c("#E69F00", "#56B4E9")) + # 定义颜色
theme_minimal() +
labs(x = "Log-transformed P-value", y = "Bubble Size (Representing Importance)", title = "KEGG Pathway Enrichment Results by Category") +
facet_wrap(~category, ncol = 1, scales = "free_y") # 按照category分组
# 可视化图
kegg_plot
```
这个例子中,`facet_wrap(~category)`会使每个类别得到单独的一列展示,`scales = "free_y"`允许每个小图自适应y轴范围。
阅读全文
相关推荐

















