其他
跟着nature communications学绘图(9) ggplot2绘制误差线点图
欢迎关注R语言数据分析指南
❝本节来进行论文图表的复现;通过ggplot2绘制误差线点图,数据及代码已经上传小编的VIP群,
❞有需要的观众老爷欢迎加入小编的VIP群
,目前已经上传「公众号文档数据+代码约170余篇」,扫描文末尾二维码加小编微信「付费99元」后邀请进群,「由于群名额有限人满之后将不在添加新成员」,有需要的请尽早加入,早进早享受;如果对加群没兴趣的观众老爷可在文末找到获取数据的方式 PI(18:1/18:1) is a SCD1-derived lipokine that limits stress signaling
加载R包
library(tidyverse)
library(ggprism)
library(ggsci)
数据清洗
df <- read_tsv("F1-b.txt") %>% pivot_longer(-c(type,time)) %>%
select(-name) %>%
group_by(type,time) %>%
summarise(value_mean=mean(value),sd=sd(value),se=sd(value)/sqrt(n())) %>%
arrange(time) %>%
filter(type !="w/o")
定义因子
❝此处由于要根据时间与类型两个因素来调整顺序因此定义两个因子
❞
df$time <- factor(df$time,levels = c("10min","1h","6h","10h","24h","48h"))
df$type <- factor(df$type,levels=read_tsv("F1-b.txt") %>% pivot_longer(-c(type,time)) %>%
select(type) %>% distinct() %>% pull())
数据可视化
❝此图虽然只是基础图形但是所包含的细节还是挺多的,需要注意的是根据需要调整各几何对象的顺序从而达到理想的结果,由于需要更改图例形状此处使用了两次「geom_point」
❞
df %>% ggplot(aes(time,value_mean,fill=type,group=type,ymin=value_mean-se,ymax=value_mean+se))+
geom_errorbar(width=0.1)+
geom_line(color="black")+
geom_point(key_glyph="polygon",aes(color=type))+
geom_point(pch=21,size=5,show.legend = F)+
scale_fill_npg()+
scale_color_npg()+
scale_x_discrete(guide = "prism_bracket")+
scale_y_continuous(limits = c(0,300),minor_breaks = seq(0,300,50), guide = "prism_offset_minor")+
annotate("text",x = 3,y=16,label="***",size=7,color="#35627F")+
labs(x=NULL,y=NULL)+
theme_prism(base_line_size =0.5)+
theme(plot.margin=unit(c(0.1,0.1,0.1,0.1),units=,"cm"),
axis.line = element_line(color = "black",size = 0.4),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(size = 0.2,color = "#e5e5e5"),
axis.text.y = element_text(color="black",size=10),
axis.text.x = element_text(margin = margin(t = -5),color="black",size=10),
legend.key=element_blank(),
legend.title = element_blank(),
legend.text = element_text(color="black",size=8),
legend.spacing.x=unit(0.1,'cm'),
legend.spacing.y=unit(1,'cm'),
legend.key.width=unit(0.7,'cm'),
legend.key.height=unit(0.4,'cm'),
legend.background=element_blank(),
legend.box.margin = margin(0,0,0,0))
数据获取
❝本节介绍到此结束,「有需要获取本篇数据的欢迎转发此文档到朋友圈,30分钟后公众号后台截图给小编」,添加小编微信时请备注来意以便高效处理,「当然更加推荐加入小编的VIP交流群」,绝让你体会到物超所值
❞
小编微信
关注下方公众号下回更新不迷路
往期推荐