Currently, we use plotSelectionProb(..., ylimext = 0.2) to make some room for the bar labels in y direction.
It would be convenient if that were automatically determined, but that seems not totally straightforward.
I tried:
- manually calculate the text width using
convertWidth(gropWidth(textGrob(text, gp = gpar(...)))) using information from ggplot_build(gg)$data[[2]], and then use that in gg + expand_limits(y), but that seems complicated
- use
geom_text_repel instead of geom_text, but that has the same issue, i.e. it constrains the labels to the plotting area
The underlying issue may be that the text dimensions are constant (given the text size and label string), while the axis size depends on the plotting device dimensions, and thus for example the axis expansion in data units would need to be re-calculated when a plot size is changed, while the text size would remain the same.
Maybe there is a more elegant solution?
Currently, we use
plotSelectionProb(..., ylimext = 0.2)to make some room for the bar labels in y direction.It would be convenient if that were automatically determined, but that seems not totally straightforward.
I tried:
convertWidth(gropWidth(textGrob(text, gp = gpar(...))))using information fromggplot_build(gg)$data[[2]], and then use that ingg + expand_limits(y), but that seems complicatedgeom_text_repelinstead ofgeom_text, but that has the same issue, i.e. it constrains the labels to the plotting areaThe underlying issue may be that the text dimensions are constant (given the text size and label string), while the axis size depends on the plotting device dimensions, and thus for example the axis expansion in data units would need to be re-calculated when a plot size is changed, while the text size would remain the same.
Maybe there is a more elegant solution?