我正在尝试在 ggplot 中添加一个段。但是,添加alpha
会导致该段消失。尽管这是许多 SO 帖子中记录的已知行为,但我遇到了一件特别奇怪的事情:当我生成情节时,reprex()
我看到了该片段,否则我没有。
示例reprex()
library(ggplot2)
library(ggforce)
df_empty_circle <-
data.frame(x = 0,
y = 0,
r = 1)
p_empty_circle <-
ggplot(df_empty_circle) +
geom_circle(mapping = aes(x0 = x, y0 = y, r = r)) +
coord_fixed() +
theme_void()
p_no_alpha <-
p_empty_circle +
annotate(geom = "segment", y = -1, yend = -1, x = -Inf, xend = 0)
p_no_alpha
p_with_alpha <-
p_empty_circle +
annotate(geom = "segment", y = -1, yend = -1, x = -Inf, xend = 0, alpha = 0.2)
p_with_alpha
由reprex 包于 2021-08-02 创建 (v2.0.0 )
运行代码时的示例reprex
好吧,和上面的代码一样,输出是:
p_no_alpha
p_with_alpha
为什么在p_with_alpha
外面运行时没有段reprex()
?
会话信息
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reprex_2.0.0 dplyr_1.0.7 ggforce_0.3.3 ggplot2_3.3.5
对此有什么解释吗?