I'm trying to add a segment in ggplot. However, adding alpha
causes the segment to disappear. Although this is a known behavior that has been documented in many SO posts, I'm experiencing a particularly strange thing: when I generate the plot with reprex()
I see the segment, but otherwise I don't.
Example with 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
Created on 2021-08-02 by the reprex package (v2.0.0)
Example when running code without reprex
Well, the same code as above, and the output is:
p_no_alpha
p_with_alpha
Why no segment in p_with_alpha
when it's run outside reprex()
?
Session Info
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
Is there any explanation for this?