美文网首页R语言可视化
可视化系列【二】:跟着Nature Communications

可视化系列【二】:跟着Nature Communications

作者: Bio_Infor | 来源:发表于2023-03-03 15:35 被阅读0次

    不积跬步,无以至千里

    本期我们同样尝试复现2023年2月27日发表在Nature Communications上的Itaconate ameliorates autoimmunity by modulating T cell imbalance via metabolic and epigenetic reprogramming文章中的Fig2A

    以下是原图:


    数据可以自行下载,也可评论区留言我私发给你。

    代码

    library(tidyverse)
    library(readr)
    library(dplyr)
    library(magrittr)
    library(ggplot2)
    
    data <- read_csv(file = 'fig3f.csv') %>% 
      pivot_longer(cols = c('Ctrl', 'ITA'), names_to = 'Category') %>% 
      na.omit()
    
    SEM <- function(vec) sd(vec, na.rm = T)/sqrt(length(!is.na(vec)))
    summary_min <- function(x) mean(x) - SEM(x)
    summary_max <- function(x) mean(x) + SEM(x)
    
    ggplot(data = data, aes(x = Category, y = value)) + 
      stat_summary(aes(color = Category),
                   geom = 'errorbar',
                   width = 0.3,
                   size = 1,
                   fun.min = summary_min,
                   fun.max = summary_max) +
      geom_bar(aes(color = Category), 
               stat = "summary", 
               fun = "mean", 
               fill = 'white', 
               size = 1, 
               width = 0.5) +
      scale_y_continuous(expand = c(0, 0), limits = c(0, 5)) +
      geom_jitter(aes(color = Category), size = 1.5, width = 0.25, fill = NA, shape = 1, stroke = 1.5) + 
      annotate(geom = 'segment', x = 1, xend = 2, y = 4.3, yend = 4.3, size = 1) +
      annotate(geom = 'text', 
               label = "paste(italic(P), \" = 0.0185\")", 
               x = 1.5, 
               y = 4.3, 
               vjust = -1, 
               family = 'sans',
               parse = TRUE) +
      labs(x = '', y = 'Inflammation score') +
      scale_color_manual(values = c('#1437B1', '#F0368E')) +
      theme_classic() +
      theme(legend.position = 'none',
            axis.title = element_text(family = 'sans', color = 'black', size = 15),
            axis.text = element_text(family = 'sans', color = 'black', size = 15),
            axis.line = element_line(color = 'black', size = 0.9),
            axis.ticks = element_line(color = 'black', size = 0.9),
            axis.ticks.length = unit(.07, units = 'in')) 
    ggsave(filename = 'Fig3f.jpeg', dpi = 5000, width = 2, height = 3)
    

    最终效果

    写在最后

    这个图里面有几个我觉得是值得我们大家一起学习的:

    • stat_summary()函数添加errorbar

    • 使用stroke参数控制空心点的边界粗细;

    • 使用label = "paste(italic(P), \" = 0.0185\")"P显示为P

    相关文章

      网友评论

        本文标题:可视化系列【二】:跟着Nature Communications

        本文链接:https://www.haomeiwen.com/subject/cjteldtx.html