复现图形
原文图形
图形绘制要点
- 数据集的准备,GO或KEGG数据结果都可以;
- 绘图所需数据:
<span class="ne-text">x = Rich, y = Descrption, size = count, color = logP, shape = Comparison</span>
;
- 可使用与两个及以上结果,将最终结果在一张图形上展现。
绘图
- 导入数据
library(ggplot2)
library(dplyr)
library(tidyr)
# 设定随机种子以保证可重复性
set.seed(42)
# 生成随机数据
KEGG_dat_long <- tibble(
Descrption = c("photosystem I", "chloroplast thylakoid", "organelles", "photosynthesis",
"biosynthesis", "response to ethylene", "mRNA binding", "RNA binding",
"cellular component", "intracellular organelle"),
Rich = runif(10, 0.005, 0.2), # 富集因子在0.005到0.2之间
count = sample(1:20, 10, replace = TRUE), # 基因数目在1到20之间
logP = runif(10, 1, 3), # -log10(Pvalue)范围在1到3之间
Comparison = sample(c("CK", "Drought"), 10, replace = TRUE) # 随机分配为"CK"或"Drought"
)
> head(KEGG_dat_long)
# A tibble: 6 × 5
Descrption Rich count logP Comparison
<chr> <dbl> <int> <dbl> <chr>
1 photosystem I 0.183 15 2.89 Drought
2 chloroplast thylakoid 0.188 7 1.16 CK
3 organelles 0.0608 4 2.03 Drought
4 photosynthesis 0.167 5 1.78 CK
5 biosynthesis 0.130 14 2.81 Drought
6 response to ethylene 0.106 20 1.89 Drought
- 绘图
ggplot(KEGG_dat_long, aes(x = Rich, y = Descrption, size = count, color = logP, shape = Comparison)) +
geom_point(alpha = 1) + # 绘制气泡图
scale_shape_manual(values = c(16, 17)) + # 16 是圆形,17 是三角形
scale_size_continuous(range = c(3, 5)) + # 调整气泡大小的范围
scale_color_gradient2(low = "#3793FE", mid = "#b3cde3", high = "red",
midpoint = median(KEGG_dat_long$logP)) + # Color gradient for log10P
labs(x = "Rich Factor", y = NULL, size = "Gene Number", shape = "Type", color = "-log10(Pvalue)") +
theme_test() +
theme(text = element_text(size = 8),
axis.text.x = element_text(size = 8, color = "black"),
axis.text.y = element_text(size = 8, colour = "black"),
strip.text = element_text(size = 8),
axis.title = element_text(size = 10),
legend.position = "right",
panel.grid.major.x = element_line(size = 0.5, linetype = "dashed", color = "gray"),
panel.spacing = unit(0.1, "lines"))
图形颜色,可结合自己的需求进行修改。
若我们的教程对你有所帮助,请点赞+收藏+转发,大家的支持是我们更新的动力!!
2024已离你我而去,2025加油!!
2024年推文汇总 (点击后访问)
2023年推文汇总 (点击后访问)
2022年推文汇总 (点击后访问)
往期部分文章
1. 最全WGCNA教程(替换数据即可出全部结果与图形)
推荐大家购买最新的教程,若是已经购买以前WGNCA教程的同学,可以在对应教程留言,即可获得最新的教程。(注:此教程也仅基于自己理解,不仅局限于此,难免有不恰当地方,请结合自己需求,进行改动。)
2. 精美图形绘制教程
3. 转录组分析教程
4. 转录组下游分析
小杜的生信筆記 ,主要发表或收录生物信息学教程,以及基于R分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!!