Partially closes #318. Builds on the same repel.R function that was introduced in the direct labels PR (#589)
pkgload::load_all("~/Documents/Projects/tinyplot") #> ℹ Loading tinyplot tinyplot(mpg ~ wt, data = mtcars, type = type_text(labels = row.names(mtcars), xpd = NA))
versus
tinyplot(mpg ~ wt, data = mtcars, type = type_text(labels = row.names(mtcars), xpd = NA, repel = TRUE))
Two limitations:
-
We don't adjust the plot region and margins in response to the text width or height, so these can overflow the plot/device region (but that's a pre-existing issue).
-
The repulsion logic operates at the group level. So, while we can guarantee that text will be dodged within groups, there may still be overlaps across groups. (Fixing this requires a more heavy-handed change to the code and will likely necessitate a second pass through the main
tinyplot.Rcode. So I'm not sure it's worth it.)
tinyplot(mpg ~ wt | factor(cyl), data = mtcars, type = type_text(labels = row.names(mtcars), xpd = NA, repel = TRUE, ))
Created on 2026-06-10 with reprex v2.1.1