Open teunbrand opened 3 weeks ago
This PR aims to fix #4327 and fix #5938.
Briefly, find_x_overlap() is completely rewritten. The trick was to search wether xmin[i + 1] is larger than cummax(xmax)[i], then start a new range.
find_x_overlap()
xmin[i + 1]
cummax(xmax)[i]
The reprex from #4327, note no misplacement of points:
devtools::load_all("~/packages/ggplot2") #> ℹ Loading ggplot2 df <- data.frame( dimension = paste0("dim ", c(1, 1, 2, 2)), group = c("A", "B", "A", "B"), value = c(0.6, 0.7, 0.4, 0.6) ) ggplot(df, aes(dimension, value, colour = group)) + geom_point(position = position_dodge2(width = 0))
Reprex from #5938, note range 3 is correctly identified as overlapping with 1 & 2.
f <- function(x, xend) find_x_overlaps(data.frame(xmin = x, xmax = xend)) df <- data.frame( xmin = c(1, 2, 3, 5), xmax = c(4, 3, 4, 6), group = factor(1:4) ) ggplot(df, aes(x = xmin, xend = xmax, y = group)) + geom_segment(aes(colour = factor(f(xmin, xmax))))
Better dodging behaviour:
ggplot(df, aes(xmin = xmin, xmax = xmax)) + geom_rect(aes(ymin = 0, ymax = 1, fill = group), alpha = 0.75, position = position_dodge2())
Time considerations in details (tl;dr: it's faster)
Created on 2024-06-07 with reprex v2.1.0
This PR aims to fix #4327 and fix #5938.
Briefly,
find_x_overlap()
is completely rewritten. The trick was to search wetherxmin[i + 1]
is larger thancummax(xmax)[i]
, then start a new range.The reprex from #4327, note no misplacement of points:
Reprex from #5938, note range 3 is correctly identified as overlapping with 1 & 2.
Better dodging behaviour:
Time considerations in details (tl;dr: it's faster)
Created on 2024-06-07 with reprex v2.1.0