如何隐藏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
相关产品推荐
相关产品推荐

