You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何隐藏ggforce中geom_mark_*注解的几何形状,保留标注线与标签

要实现保留引线和标签、隐藏圈选几何形状的需求,直接对geom_mark_*系列函数设置fill = NA和color = NA即可,这两个参数分别控制圈选形状的填充色和边框色,设为NA后形状会完全透明,不会受多背景色的影响,也不会遮挡下层图层。

你提供的示例修改后代码如下:

library(tidyverse)
library(ggforce)

df2 <- tibble(
  x = 1:10,
  y = rnorm(10),
  z = LETTERS[1:10]
)

ggplot(df2, aes(x, y)) +
  geom_point() +
  geom_mark_circle(
    aes(label = z, filter = x == 5),
    fill = NA, # 隐藏圆形填充
    color = NA # 隐藏圆形外边框
  ) +
  annotate(
    "rect",
    xmin = 0, 
    xmax = 5,
    ymin = -Inf,
    ymax = Inf,
    fill = "steelblue",
    alpha = 0.3
  ) +
  annotate(
    "rect",
    xmin = 5, 
    xmax = Inf,
    ymin = -Inf,
    ymax = Inf,
    fill = "firebrick",
    alpha = 0.3
  )

如果你使用其他geom_mark_*函数(比如geom_mark_rect、geom_mark_hull等),这个参数设置方法同样适用。

内容的提问来源于stack exchange,提问作者David Ranzolin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 06:57:04