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

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

作者: Bio_Infor | 来源:发表于2023-02-27 00:54 被阅读0次

    不积跬步,无以至千里

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

    以下是原图:


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

    代码

    library(ggplot2)
    library(tidyverse)
    library(tidyr)
    library(readr)
    
    data <- read_csv(file = 'data.csv',
                     skip = 1,
                     col_names = c('Day', paste('Ctrl', 1:11, sep = "_"), paste('ITA', 1:11, sep = "_")))
    SEM <- function(vec) sd(vec)/sqrt(length(vec))
    
    #control
    data %>% 
      select(starts_with('Ctrl')) %>% 
      {
        mean = apply(., MARGIN = 1, FUN = mean)
        sem = apply(., MARGIN = 1, FUN = SEM)
        data.frame(class = rep('Ctrl', nrow(data)),
                   days = factor(1:nrow(data), levels = 1:nrow(data)),
                   mean = mean,
                   sem = sem)
      } -> ctrl
    #ita
    data %>% 
      select(starts_with('ITA')) %>% 
      {
        mean = apply(., MARGIN = 1, FUN = mean)
        sem = apply(., MARGIN = 1, FUN = SEM)
        data.frame(class = rep('ITA', nrow(data)),
                   days = factor(1:nrow(data), levels = 1:nrow(data)),
                   mean = mean,
                   sem = sem)
      } -> ita
      
    rbind(ctrl, ita) %>%
      ggplot(aes(x = days, y = mean)) + 
      geom_line(aes(group = class, color = class), size = 1) + 
      geom_point(aes(color = class), shape = 1, size = 2, stroke = 1.5) + 
      geom_errorbar(aes(ymin = mean - sem, ymax = mean + sem, color = class), size = 1, width = 0.6) +
      scale_color_manual(values = c('#8B8D23', '#028C8F')) + 
      scale_y_continuous(limits = c(0, 4)) +
      scale_x_discrete(breaks = c(0, 5, 10, 15)) +
      theme_classic() +
      labs(x = 'Day', y = 'Clinical score') +
      theme(legend.position = c(0.15, 0.9),
            legend.background = element_blank(),
            legend.title = element_blank(),
            axis.title = element_text(family = 'sans', color = 'black'),
            axis.text = element_text(family = 'sans', color = 'black'),
            axis.line = element_line(color = 'black', size = 1),
            axis.ticks = element_line(color = 'black', size = 1)) + 
      annotate(geom = 'segment', x = 16, xend = 16, y = 1.4, yend = 2.7, size = 1) + 
      annotate(geom = 'segment', x = 15.5, xend = 16, y = 1.4, yend = 1.4, size = 1) +
      annotate(geom = 'segment', x = 15.5, xend = 16, y = 2.7, yend = 2.7, size = 1) +
      annotate(geom = 'text', label = 'P = 0.0001', angle = 90, x = 17, y = 2.15, vjust = "left", hjust = "center")
    

    最终效果

    写在最后

    • 原始图中errorbar只显示了一半,这可以通过geom_segment()来实现,但在这里我没有做。

    • 关于原图中的P如何显示成为P,目前我还没有找到一个好办法。

    相关文章

      网友评论

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

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