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
It would be nice to have control of the ordering of labels.
Minimal code example
Related to issue #200 that I filed today. It would be neat to order the boxes in decreasing or ascending order from left to right, bottom to top. I.e. now the order depends on the seed but would it be possible to have a logical order?
library(dplyr)
library(ggplot2)
library(ggrepel)
set.seed(42)
mpg %>%
group_by(manufacturer, model) %>%
summarize(cty= mean(cty, na.rm=TRUE)) %>%
ggplot(aes(x=cty, y=1,
label= paste0(manufacturer, "\n", model))) +
geom_point(alpha=.3) +
geom_label_repel(
fill="grey90",
nudge_y=.03,
direction="y",
hjust=.5,
max.iter=1e4, max.time=1,
size=1, ## tiny for reprexlineheight=.9
) +
xlim(5, 30) +
ylim(1, 0.95) +
theme_void()
#> `summarise()` has grouped output by 'manufacturer'. You can override using the `.groups` argument.#> Warning: ggrepel: 13 unlabeled data points (too many overlaps). Consider#> increasing max.overlaps
A potentially more insightful example is this one. Here I would like to order the boxes from top to bottom in the same order as they appear in time (along the x axis). Basically, every time ggrepel needs to place a label in a lower row, please you first the remaining one with the lowest x value before trying one with a higher x value.
Suggestions
Not sure it easy to solve since the boxes are placed in random order (I assume), one by one. But that could be also the point to start with. First place box 1, afterwards box 2 and so on.
This can be solved using nudging. Function positiion_nudge_to() from package ggpp solves this problem. It takes a vector of nudgings, so by manually or programatically computing these distances you can move the initial positions for the repulsion, or the final position if you set iterations to zero. NOTE: This requires ggrepel under development and ggpp (>= 0.4.2) from CRAN.
Summary
It would be nice to have control of the ordering of labels.
Minimal code example
Related to issue #200 that I filed today. It would be neat to order the boxes in decreasing or ascending order from left to right, bottom to top. I.e. now the order depends on the seed but would it be possible to have a logical order?
Created on 2021-07-14 by the reprex package (v1.0.0)
A potentially more insightful example is this one. Here I would like to order the boxes from top to bottom in the same order as they appear in time (along the x axis). Basically, every time ggrepel needs to place a label in a lower row, please you first the remaining one with the lowest x value before trying one with a higher x value.
Suggestions
Not sure it easy to solve since the boxes are placed in random order (I assume), one by one. But that could be also the point to start with. First place box 1, afterwards box 2 and so on.
Version information
The text was updated successfully, but these errors were encountered: