前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >跟着Nature学作图:R语言ggplot2分组散点图并添加误差线

跟着Nature学作图:R语言ggplot2分组散点图并添加误差线

作者头像
用户7010445
发布2023-08-23 10:43:15
7370
发布2023-08-23 10:43:15
举报
文章被收录于专栏:小明的数据分析笔记本

论文

Telomere-to-mitochondria signalling by ZBP1 mediates replicative crisis

https://www.nature.com/articles/s41586-023-05710-8

s41586-023-05710-8.pdf

大部分图的原始数据都有,争取把有原始数据的图都用R语言来复现一下

41586_2023_5710_MOESM4_ESM (1).xlsx

今天的推文复现一下论文中的Fig1c

image.png

论文中提供的数据集部分截图

image.png

手动整理成如下格式

image.png

然后按照行求均值和均值标准误sem

代码语言:javascript
复制
library(readxl)
library(tidyverse)

dat<-read_excel("data/20230521/figure1c.xlsx")
head(dat)

plotrix::std.error(c(1,2,3))

dat %>% 
  rowwise() %>% 
  mutate(mean_value=mean(c(rep1,rep2,rep3)),
         std_error=plotrix::std.error(c(rep1,rep2,rep3))) %>% 
  ungroup() -> new.dat

作图代码

代码语言:javascript
复制
dat %>% 
  rowwise() %>% 
  mutate(mean_value=mean(c(rep1,rep2,rep3)),
         std_error=plotrix::std.error(c(rep1,rep2,rep3))) %>% 
  ungroup() -> new.dat

ggplot(data=new.dat,aes(x=time,y=mean_value,color=group))+
  
  geom_errorbar(aes(ymin=mean_value-std_error,
                    ymax=mean_value+std_error),
                width=0.4)+
  geom_point(size=5)+
  scale_color_manual(values = c("A"="#000000",
                                "B"="#7bd2f6",
                                "D"="#094c8b",
                                "E"="#cbc08c",
                                "F"="#f27c79"),
                     labels=c("Vector","mRHIM2","mRHIM1",expression(paste("mZ",alpha,"2")),"WT"),
                     breaks = c("A","F","E","D","B"),
                     name=NULL)+
  scale_x_continuous(limits = c(0,40),
                     expand = expansion(mult=c(0,0)),
                     breaks = seq(0,36,4))+
  coord_cartesian(clip = "off")+
  theme_classic()+
  theme(legend.text = element_text(hjust=0),
        legend.position = c(0.1,0.8))+
  labs(x="Time (h)",
       y=expression(paste("Dead cells per ",mm^2," (%)")))+
  annotate(geom = "segment",x=37,xend=37,y=5,yend=28)+
  annotate(geom = "segment",x=37,xend=37-0.2,y=28,yend=28)+
  annotate(geom = "segment",x=37,xend=37-0.2,y=5,yend=5)+
  annotate(geom="text",x=37.5,y=17,label="*\n*\n*")+
  annotate(geom = "segment",x=38,xend=38,y=5,yend=33)+
  annotate(geom = "segment",x=38,xend=38-0.2,y=33,yend=33)+
  annotate(geom = "segment",x=38,xend=38-0.2,y=5,yend=5)+
  annotate(geom="text",x=38.5,y=19,label="*\n*\n*")

image.png

推文记录的是自己的学习笔记,内容可能会存在错误,请大家批判着看,欢迎大家指出其中的错误

示例数据和代码可以给推文打赏一元获取,或者找到论文中的数据自己手动整理

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-05-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 论文
  • 作图代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档