复现Nature genetics图,换数据即可用!
本次使用R语言复现一下Nature genetics中的b图!
❤️复现效果图❤️
✅R语言复现
ggplot(iris_data, aes(x = species, y = sepal_length, fill = species)) +
# 添加上侧半边violin plot
geom_half_violin(aes(fill = species), position = position_nudge(x = 0.20), side = "r", alpha = 0.6) +
# 添加中间box plot
geom_boxplot(aes(x = species, y = sepal_length, fill = 'black'), position = position_nudge(x = -0.35), width = .35, alpha = 0.0)+
# 添加下侧抖动point plot
geom_point(aes(x = species, y = sepal_length, fill = species), position = position_jitter(width = .10), shape = 21, size = 3, stroke = 0.5, alpha = 0.6)+
# 添加统计p值
geom_signif(
comparisons = list(
c("setosa", "versicolor"),
c("versicolor", "virginica"),
c("setosa", "virginica")
),
map_signif_level = TRUE, # 显示星号p值
test = "t.test", # 使用t检验
tip_length = 0.01, # 调整横线末端长度
y_position = c(8.5, 9.0, 9.5) # 设置标记的垂直位置,避免重叠
) +
# 设置填充颜色为自定义颜色向量 custom_colors1
scale_fill_manual(values = custom_colors1) +
# 应用自定义主题控制图表外观
custom_theme +
coord_flip()
该图由boxplot、jitter point 、half violin以及统计p值4部分构成:
展示了原始数据的点(jitter point ); 展示了数据的统计分布(boxplot + half violin); 同时展示了各组间的统计p值。
也可将“*”格式p值切换为数字p值,map_signif_level = TRUE修改为map_signif_level = function(p) sprintf("%.2f", p)即可,
✅“*”与数值对应关系:
*: 1.00e-02 < p <= 5.00e-02 **: 1.00e-03 < p <= 1.00e-02 ***: 1.00e-04 < p <= 1.00e-03 ****: p <= 1.00e-04
✅使用自己数据
iris_data换做自己数据集,
本期结束!
(加入学习,收费,备注:299)