pythonic生物人

复现中科院IF 25.9期刊上3张图,换数据即可用!

看到中科院Cell Research上的几张图,这些图是科研论文中常用的图,

ref: s41422-023-00923-y
ref: s41422-023-00923-y

下面使用R语言复现一下c、h、j图,替换为自己数据即可使用!


复现效果图-图c
复现效果图-图c
复现效果图-图h
复现效果图-图h
复现效果图-图j
复现效果图-图j

R绘制-c图

c图是一张普通的折线图,展现"hChKA" 和"hMfsd7c + hChKA"两组数据随着时间的变化趋势。

  • 读入数据
Image
  • 关键代码
# 绘图
ggplot(line_cr_data, aes(x = Time, y = Value, color = Group, shape = Group)) +
  geom_line(size = 0.5) +
  geom_point(size = 3) +

# 两组数据显著性标记
  geom_text(
    data = subset(line_cr_data, Group == "hMfsd7c + hChKA" & Time > 0),
    aes(label = "***"), vjust = -0.8, size = 7, color = "black"
  ) +

# 坐标轴设置
  scale_x_continuous(
    breaks = x_breaks,
    labels = x_labels,
    limits = c(0, 125),
    expand = c(0.0, 0),
    name = "Time (mins)"
  ) +
  scale_y_continuous(
    breaks = y_breaks,
    labels = y_labels,
    limits = c(0, 17500),
    expand = c(0, 0),
    name = NULL
  ) +

# line样式
  scale_color_manual(values = color_values) +
  scale_shape_manual(values = shape_values) +

# 细节修改
  theme_classic()
Image

✅值得学习的R可视化知识点:

  • 两组数据差异统计显著性标记添加,这里直接使用geom_text将已知道的显著性“***”添加到图中,

  geom_text(
    data = subset(line_cr_data, Group == "hMfsd7c + hChKA" & Time > 0),
    aes(label = "***"), vjust = -0.8, size = 7, color = "black"
  )
Image
  • *含义

***:P < 0.0001

**:P < 0.01

*:P < 0.05 

  • 连续性坐标轴设置,使用scale_x_continuous和scale_y_continuous,
# 坐标轴设置
  scale_x_continuous(
    breaks = x_breaks,
    labels = x_labels,
    limits = c(0, 125),
    expand = c(0.0, 0),
    name = "Time (mins)"
  ) +
  scale_y_continuous(
    breaks = y_breaks,
    labels = y_labels,
    limits = c(0, 17500),
    expand = c(0, 0),
    name = NULL
  )
  • 原图添加的error bar,可以通过每个点做3个重复数据点实现,
Image

R绘制-h图

h图展示"Before release"和"After release"两种状态下,三组数据组内之间的统计显著性,使用boxplot联合抖动散点图,

  • 读入数据
Image
  • 关键代码

ggplot(bar_cr_data, aes(x = Group, y = DPM, color = Time)) +

# 绘制柱状图
  stat_summary(
    fun = mean, geom = "bar",
    position = position_dodge(0.8),
    width = 0.7,
    fill = NA,
    size = 0.5,
    show.legend = FALSE
  ) +

# 绘制error bar
  stat_summary(
    fun.data = mean_se, geom = "errorbar",
    position = position_dodge(0.8),
    width = 0.25,
    size = 0.5,
    show.legend = FALSE
  ) +
# 绘制散点图
  geom_point(aes(shape = Time),
    position = position_jitterdodge(
      jitter.width = 0.2,
      dodge.width = 0.8
    ),
    size = 2.5
  ) +
  scale_color_manual(values = c(
"Before release" = "black",
"After release" = "red"
  )) +
  scale_shape_manual(values = c(
"Before release" = 19,
"After release" = 1
  )) +

# 添加显著性标记的横线
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x2, y = y, yend = y),
    inherit.aes = FALSE, size = 0.5, color = "black"
  ) +
# 添加显著性标记的左右侧竖线
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x1, y = y, yend = y - 100),
    inherit.aes = FALSE, size = 0.5, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x2, xend = x2, y = y, yend = y - 100),
    inherit.aes = FALSE, size = 0.5, color = "black"
  ) +

# 添加显著性标记文本
  geom_text(
    data = sig_df,
    aes(x = (x1 + x2) / 2, y = y + 100, label = label),
    inherit.aes = FALSE, size = 7
  ) 
Image

✅值得学习的R可视化知识点:

  • error bar添加方法,使用ggplot2的stat_summary,
stat_summary(
    fun.data = mean_se, geom = "errorbar",
    position = position_dodge(0.8),
    width = 0.25,
    size = 0.5,
    show.legend = FALSE
  )
Image
  • ns含义:

ns: 5.00e-02 < p <= 1.00e+00

  • geom_segment绘制直线线段
# 添加显著性标记的横线
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x2, y = y, yend = y),
    inherit.aes = FALSE, size = 0.5, color = "black"
  ) +
# 添加显著性标记的左右侧竖线
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x1, y = y, yend = y - 100),
    inherit.aes = FALSE, size = 0.5, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x2, xend = x2, y = y, yend = y - 100),
    inherit.aes = FALSE, size = 0.5, color = "black"
  )
Image

当然,ggsignif等一些现成的方法也可以做,但geom_segment更加灵活。


R绘制-j图

j图展示100和200 µM两种条件处理下,三组数据组内和组间之间的统计显著性(区别于原图,这里增加了组间比较、组间分割线等),使用无框boxplot联合抖动散点图,

  • 读入数据
Image
  • 关键代码
ggplot() +
  geom_quasirandom(
    data = bar_cr1_data,
    aes(x = Condition, y = Value, color = Group),
    size = 3, width = 0.2, alpha = 0.8
  ) +
  geom_point(
    data = summary_data,
    aes(x = Condition, y = Mean),
    size = 5, shape = 18, color = "black"
  ) +
  geom_errorbar(
    data = summary_data,
    aes(x = Condition, ymin = Mean - SE, ymax = Mean + SE),
    width = 0.12, size = 0.6, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x2, y = y, yend = y),
    size = 0.3, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x1, xend = x1, y = y, yend = y - 1),
    size = 0.3, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x2, xend = x2, y = y, yend = y - 1),
    size = 0.3, color = "black"
  ) +
  geom_text(
    data = sig_df,
    aes(x = (x1 + x2) / 2, y = y, label = label),
    size = 7, vjust = 0
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x1_con, xend = x2_con, y = y_con, yend = y_con),
    size = 0.3, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x1_con, xend = x1_con, y = y_con, yend = y_con - 1),
    size = 0.3, color = "black"
  ) +
  geom_segment(
    data = sig_df,
    aes(x = x2_con, xend = x2_con, y = y_con, yend = y_con - 1),
    size = 0.3, color = "black"
  ) +
  geom_text(
    data = sig_df,
    aes(x = (x1_con + x2_con) / 2, y = y_con, label = label_con),
    size = 7, vjust = 0
  ) +
  scale_color_manual(values = c("blue", "red", "green")) +
  scale_y_continuous(
    limits = c(0, 50),
    breaks = seq(0, 50, by = 10),
    expand = expansion(mult = c(0, 0.1))
  ) +
  labs(
    x = "",
    y = "ΔV (mV)",
    color = ""
  ) +
  theme_classic() +

#添加辅助分割线
  annotate(
"segment",
    x = 3.5, xend = 3.5, y = 0, yend = 50,
    linetype = "dashed",
    color = "gray50"
  )
Image

✅值得学习的R可视化知识点:

  • 这张图方法与h图类似,相比原图改动见下图,
Image

测试数据+详细代码,后期会加入👉《保姆级R可视化教程》来了!

加入学习(备注:299)

图片