第10讲:专业注释与标记——图中添加显著性、箭头、分组说明的技巧

目录

🧩 1. 显著性标记(Significance Annotation)

(1)手动添加显著性符号

(2)用ggpubr::stat_compare_means()

🚀 2. 箭头与指引标记(Arrow Annotation)

(1)用annotate(“segment”)绘制箭头

✍️ 3. 分组说明与图内标签(Group Annotation)

(1)用annotate(“text”)直接加

(2)更正式的方法:ggsignif包自动加括号和显著性

🌈 4. 图表注释综合实战小案例

🧠 小结:科研绘图注释秘籍

🔥 预告:第11讲

一张优秀的科研图表,不仅展现数据,还要清晰表达重点
注释(annotation)就是让你的图表会”说话”的秘密武器!

本讲,我们来系统掌握:
显著性标注、分组标签、箭头指引、文本说明等技巧,
让你的图不仅美观,还精准传递科研信息!


🧩 1. 显著性标记(Significance Annotation)

在柱形图、箱线图等比较类图形中,经常需要添加
* ** ***
标注统计显著性水平。

(1)手动添加显著性符号

最简单的方法:使用annotate()函数或geom_text()直接添加。

library(ggplot2)

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot() +
  geom_text(aes(x = 2, y = 30, label = "**"), size = 6)

xy:指定位置

label = "**":符号内容

size:文字大小

(2)用ggpubr::stat_compare_means()

更自动化的方法,适合正式SCI图表!

library(ggpubr)

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot() +
  stat_compare_means(comparisons = list(c("4", "6"), c("4", "8")),
                     method = "t.test")

comparisons指定比较组

method可以是t.testwilcox.test

✅ 让显著性分析+标注一气呵成,非常专业!


🚀 2. 箭头与指引标记(Arrow Annotation)

想强调某个点或趋势?
加个箭头直接指向!

(1)用annotate("segment")绘制箭头

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  annotate("segment", 
           x = 4, xend = 5, 
           y = 15, yend = 10, 
           arrow = arrow(length = unit(0.2, "cm")),
           color = "red", size = 1)

x, y 起点;xend, yend 终点

arrow()添加箭头头部

colorsize自定义样式

✅ 红色箭头醒目直观,非常适合突出异常点、趋势转折!


✍️ 3. 分组说明与图内标签(Group Annotation)

有时候我们希望标出不同组
比如在箱线图上方加上组名或比较描述。

(1)用annotate("text")直接加

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot() +
  annotate("text", x = 1, y = 35, label = "Group A", size = 5) +
  annotate("text", x = 2, y = 35, label = "Group B", size = 5)

(2)更正式的方法:ggsignif包自动加括号和显著性

library(ggsignif)

ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot() +
  geom_signif(comparisons = list(c("4", "6")),
              map_signif_level = TRUE)

✅ 轻松加上 一条带括号的比较线+显著性符号


🌈 4. 图表注释综合实战小案例

完整示例:
显著性、箭头、分组注释一次集齐!

library(ggplot2)
library(ggpubr)

p <- ggplot(mtcars, aes(x = factor(cyl), y = mpg)) +
  geom_boxplot(fill = "lightblue") +
  stat_compare_means(comparisons = list(c("4", "6"), c("4", "8")),
                     label = "p.signif", method = "t.test") +
  annotate("segment", x = 1, xend = 2, y = 30, yend = 25,
           arrow = arrow(length = unit(0.25, "cm")), color = "red") +
  annotate("text", x = 2.5, y = 31, label = "Notice Group 6", size = 5)

print(p)

 

结果图:

添加了显著性比较符号

标注箭头指向重点

高位文字注释说明

✅ 专业感和阅读体验直接拉满!


🧠 小结:科研绘图注释秘籍

注释内容 推荐方法
显著性标记 stat_compare_means()(自动) or annotate()(手动)
箭头指引 annotate("segment")
组内说明 annotate("text") or geom_signif()
注释风格 简洁、规范,字体大小统一,不影响数据本身

🔥 预告:第11讲

下一讲,我们将进入
🔵 “分面(Facet)设计艺术——多组数据的优雅排列与统一美学”

📈 多子图布局,让科研图表更加系统有序!


© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容