Closed acgoodman closed 8 months ago
Thank you for the reprex!!!
@slowkow @acgoodman I think the reason for the difference is not necessarily the length of the labels. It is possible that the numbers have vertically smaller bounding boxes than the capital letters in the same font, or the box padding or box size is influenced in some way by the text. The labels using capital letters do not seem fit in the available space with the default box padding. After decreasing the box.padding they barely fit into the available space.
I would not consider this to be a bug.
library(ggplot2)
library(ggrepel)
ggplot(mtcars[order(mtcars$disp), ], aes(mpg, disp))+
geom_point()+
geom_label_repel(
aes(label = row.names(mtcars)), # label by rowname
nudge_x = Inf,
direction = "y",
force = 0.5,
force_pull = 0.1,
box.padding = 0.06,
max.time = 4,
max.iter = 1e5)+
scale_x_continuous(expand = expansion(mult=c(0.1,1)))
ggsave(filename="plot2a.png", width=4, height=8, units = "in")
# long labels NO LONGER overlap with each other
Even without widening the plotting area, as above, the algorithm works within what is possible.
I have noticed in general is that if the space is very tight to avoid the labels "jumping around" one needs to decrease the forces and increase the number of iterations/time.
ggsave(filename="plot2a.png", width=3, height=8, units = "in")
# long labels NO LONGER overlap with each other
Summary
geom_*_repel()
appears to be sensitive to label length and horizontal justification during vertical repulsion in narrow plots. This seems at first glance to be distinct from other justification issues.Minimal code example
Version information
Here is the output from
sessionInfo()
in my R session:This is my first github issue! Hopefully there is enough information here.