- 跟着Nature Communications 学画图~ggpl
- 第一个跟着Nature Communications学画图系列合
- 跟着Nature Communications 学画图~ggpl
- R语言基础绘图函数散点图~跟着Nature Communicat
- 跟着Nature Communications 学画图~ggpl
- 跟着Nature Communications学画图~Figur
- 跟着Nature Communications学画图~Figur
- 跟着Nature Communications学画图
- 跟着Nature Communications学作图 -- 复杂
- 跟着Nature Communications学作图:synvi
不积跬步,无以至千里
本期我们尝试“部分”复现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
,目前我还没有找到一个好办法。
网友评论