当前位置: 首页 > article >正文

R语言绘图

多组火山图

数据准备:

将CSV文件同一在一个路径下,用代码合并

确保文件列名正确

library(fs)
library(dplyr)
library(tidyr)
library(stringr)
library(ggplot2)
library(ggfun)
library(ggrepel)

# 获取文件列表
file_paths <- dir_ls(path = "E:\\proteomic\\fuxian_bacteria\\multivolcano", pattern = "_DEG\\.csv$", full.names = T)
# 检查文件列表
print(file_paths)

# 读取和处理数据
all_deg <- map(file_paths, function(x){
  # 检查文件扩展名,忽略大小写
  if (str_ends(str_to_lower(x), ".csv")) {
    cat("Processing file:", x, "\n") # 打印正在处理的文件名
    data <- read_delim(file = x, col_names = T, delim = ",")
    if (is.data.frame(data)) {
      group <- str_remove(basename(x), pattern = "_DEG.*")
      return(dplyr::mutate(data, group = group))
    } else {
      cat("Failed to read file:", x, "\n")
      return(NULL)
    }
  } else {
    cat("Skipping non-CSV file:", x, "\n")
    return(NULL)
  }
}) %>%
  compact() %>% # 移除列表中的 NULL 元素
  do.call(rbind, .)

ggplot(data = all_deg) +
  geom_jitter(data = all_deg %>% dplyr::filter(change == "Normal"),
              aes(x = group, y = logFC, color = change, size = abs(logFC), alpha = abs(logFC)),
              width = 0.4) +
  geom_jitter(data = all_deg %>% dplyr::filter(change != "Normal"),
              aes(x = group, y = logFC, color = change, size = abs(logFC), alpha = abs(logFC)),
              width = 0.4) +
  geom_jitter(data = all_deg %>% dplyr::group_by(group) %>%
                dplyr::arrange(desc(abs(logFC))) %>%
                dplyr::slice_head(n = 15) %>%
                dplyr::ungroup() %>%
                na.omit(),
              aes(x = group, y = logFC, size = abs(logFC)),
              width = 0.4, shape = 21, fill = "#e77381") +
  geom_text_repel(data = all_deg %>% dplyr::group_by(group) %>%
                    dplyr::arrange(desc(abs(logFC))) %>%
                    dplyr::slice_head(n = 15) %>%
                    dplyr::ungroup() %>%
                    na.omit(),
                  aes(x = group, y = logFC, label = SYMBOL)) +
  geom_tile(aes(x = group, y = 0, fill = group), height = 0.4) +
  geom_text(data = all_deg %>% dplyr::select(group) %>% dplyr::distinct(group, .keep_all = T),
            aes(x = group, y = 0, label = group), size = 6) +
  geom_hline(yintercept = c(-log2(1.5), log2(1.5))) +
  scale_y_continuous(limits = c(-5, 5)) +
  scale_size(range = c(1, 10)) +
  scale_alpha(range = c(0.1, 1)) +
  scale_color_manual(values = c("Up" = "#f46d43", "Normal" = "#bdbdbd", "Down" = "#3288bd")) +
  scale_fill_manual(values = c('#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3')) +
  theme_bw() +
  theme(axis.text = element_text(color = "#000000", size = 12),
        axis.title = element_text(color = "#000000", size = 15),
        panel.grid = element_blank(),
        legend.background = element_roundrect(color = "#969696")) +
  labs(y = "log2(Fold Change)")


http://www.kler.cn/a/508379.html

相关文章:

  • 国产编辑器EverEdit - 复制为RTF
  • php-2025面试题准备
  • Spring框架 了解
  • 【Git版本控制器--1】Git的基本操作--本地仓库
  • AIGC时代:如何快速搞定Spring Boot+Vue全栈开发
  • Web第一次作业
  • go语言gui窗口应用之fyne框架-自定义容器实现自定义布局,更灵活的显示控件
  • sparkSQL练习
  • 使用FineBI进行数据分析(入门级)
  • 天机学堂3-ES+Caffeine
  • 多个页面一张SQL表,前端放入type类型
  • C++实现设计模式---中介者模式 (Mediator)
  • 【机器学习:三十三(一)、支持向量机】
  • YOLOv11改进,YOLOv11检测头融合RFAConv卷积,并添加小目标检测层(四头检测),适合目标检测、分割等任务
  • RV1126+FFMPEG推流项目(7)AI音频模块编码流程
  • 游戏引擎学习第80天
  • VTK知识学习(36)-图像平滑
  • 【spark源码修改】hive3.1.3 spark3.5.4编译,需要修改源码,最终编译成功
  • 全国青少年信息学奥林匹克竞赛(信奥赛)备考实战之一维数组(应用技巧)
  • linux 国产化命令
  • 算法随笔_10: 供暖器
  • Linux网络 TCP socket
  • 一体机cell服务器更换内存步骤
  • java 小红书源码 1:1还原 uniapp
  • 小识MySQL中的OLTP和OLAP
  • 全类别机器人传感器模块推荐