复现Nature期刊图,换数据即可用!
R语言复现一下Nature中的c图,PCA标记图。
❤️复现效果图❤️,
R语言复现
该图为PCA图+椭圆置信区间+marker分类+颜色分类+text标记的组合图。下面一步步复现它!
PCA图
ggpca联合ggplot2完成,
ggpca(
iris_data,
metadata_cols = c("species", "type", "id"),
mode = "pca",
color_var = "species",
ellipse = FALSE
)
椭圆置信区间
stat_ellipse完成
stat_ellipse(
aes(color = species, fill = species),
geom = "polygon", alpha = 0.2, linewidth = 0.01
)
marker分类
三角形、圆形、方形标记亚分类,
geom_point(
aes(color = species, fill = species, shape = type)
)
text标记
一些特别关注的点,添加原始数据、添加直线指引,
geom_text_repel(
data = highlight_pca,
aes(
x = PC1,
y = PC2,
label = paste0("(", sepal_length, ", ", sepal_width, ")")
))
最终,搞定,
本期结束!
测试数据+详细代码,即将会加入👉2026可视化工具TOP3
加入学习(备注:299)