You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
geom_area does not align with geom_line with duplicate x coords #5227
When x coordinates are duplicated geom_area does not align with geom_line. For example, in the following example, some of the x=2 coordinates are shifted back slightly (but visibly).
library(ggplot2) # ggplot2_3.4.1data.frame(x= c(1,2,2,3), y=4:1) |>tidyr::crossing(id= c(0, 1e2)) |>
ggplot(aes(x+id, y)) +
facet_wrap(vars(id), scales='free_x') +
geom_area() +# not aligned with lines from next geom_line
geom_line()
While each panel has a range of 2 on the x-axis, this fudge factor becomes 0.001 * 103 = 0.103 units, which is visible. I think it might be best to do the alignment calculations per panel instead of for the data as a whole. The stacking, that stat = "align" makes easier, applies on a panel-level rather than the whole data level as well.
Activity
teunbrand commentedon Mar 13, 2023
Thanks for the report, I can reproduce the issue. Here is the plot rendered:
Created on 2023-03-13 with reprex v2.0.2
Ultimately, I think this turns out less than ideal due to the fudge factor of 0.001 used in this line:
ggplot2/R/stat-align.R
Line 49 in 04a5ef2
While each panel has a range of 2 on the x-axis, this fudge factor becomes
0.001 * 103 = 0.103units, which is visible. I think it might be best to do the alignment calculations per panel instead of for the data as a whole. The stacking, thatstat = "align"makes easier, applies on a panel-level rather than the whole data level as well.