pythonic生物人

复现Nature communications期刊图,换数据即可用!

本次使用R语言复现一下Nature communications中的1张图,以及它的12种玩法!

s41467-024-51355-0,Figure2c 原图
s41467-024-51355-0,Figure2c 原图
❤️复现效果图-Figure2c ❤️
❤️复现效果图-Figure2c ❤️

✅读入测试数据

Image

✅玩法1: boxplot + jitter point + half violin

原图由boxplot、jitter point 、half violin以及统计p值4部分构成:

  • 即展示了原始数据的点(jitter point );
  • 又展示了数据的统计分布(boxplot);
  • 3类图组合又节约版面空间(boxplot +jitter point + half violin);

一举3得!

# 核心代码
ggplot(iris_data, aes(x = species, y = sepal_length, fill = species)) +

# 添加右侧半边小提琴图
  geom_half_violin(aes(fill = species)) +

# 左侧boxplot
  geom_boxplot(aes(x = species, y = sepal_length, fill = 'black'))+

# 左侧jitter point
  geom_point(aes(x = species, y = sepal_length, fill = species),position = position_jitter(width = .15))+

# 统计p值
  geom_signif(
    comparisons = list(
      c("setosa", "versicolor"),
      c("versicolor", "virginica"),
      c("setosa", "virginica")
    ),
    map_signif_level = TRUE,  # 显示星号标记而非具体p值
    y_position = c(8.5, 9.0, 9.5)  # 设置标记的垂直位置,避免重叠
  )
Image

当然,这张图可以有更多玩法!


✅玩法2: boxplot + jitter point + half violin(水平)

只需使用coord_flip()即可,

# 核心代码
  coord_flip()
Image

✅玩法3: boxplot + jitter point + half violin(分开显示)

将boxplot、jitter point、half violin三图不组合在一起,通过添加position参数实现,

Image
Image

✅玩法4: boxplot + jitter point + half violin(分开显示 + 水平)

玩法3的基础上使用coord_flip()即可,

Image

✅玩法5: boxplot + jitter point(分开显示)

玩法4的基础上去half violin即可,同时调整position,

Image

✅玩法6: boxplot + jitter point(分开显示 + 水平)

玩法5的基础上使用coord_flip()即可,

Image

✅玩法7: boxplot + jitter point(组合显示)

玩法5的基础上调整position,

Image

✅玩法8: boxplot + jitter point(组合显示 + 水平)

玩法7的基础上使用coord_flip()即可,

Image

✅玩法9: half boxplot + half jitter point(分开显示)

全部使用geom_half_xx代替geom_xx即可,

Image

✅玩法10: half boxplot + half jitter point(分开显示 + 水平)

玩法9的基础上使用coord_flip()即可,

Image

✅玩法11: half violin + half jitter point(分开显示)

玩法9的基础上替换violin方法即可,

Image

✅玩法12: half violin + half jitter point(分开显示 + 水平)

上一玩法基础上添加coord_flip()即可,

Image

本期结束!


测试数据+详细代码即将加入:《👉保姆级R可视化教程2.0》,39个章节,20w字+,数百张图,旨在引导如何系统学习R语言可视化,

(加入学习,备注:299)

图片
部分展示如下:
图片
图片
图片
图片
图片
图片
复现效果图-abcd图❤️
复现效果图-b图❤️
图片
❤️复现效果图-ABCD图❤️
图片
❤️复现效果图-bcd图❤️
图片
图片
❤️复现效果图-b图❤️
图片
图片
图片
图片
图片
图片
图片
图片
图片
图片

图片

图片
图片

(加入学习,收费,备注:299)

图片