Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip text on the same column as the axis text #5344

Closed
oliviercailloux opened this issue Jul 6, 2023 · 1 comment
Closed

Strip text on the same column as the axis text #5344

oliviercailloux opened this issue Jul 6, 2023 · 1 comment

Comments

@oliviercailloux
Copy link

oliviercailloux commented Jul 6, 2023

It is well known that long strip text can be a problem. Displaying them vertically hurts readability (if at all feasible). Displaying them horizontally next to the axis text may make the figure too wide: horizontal space is usually much restricted, especially in publications.

One solution to this conundrum is to display the strip text on top of the axis text, rather than on the side of it. As in the following figure for example (source).
thoraxjnl-2020-September-75-9-735-F3 large
What I mean here with "strip text" is "Yearly excacerbations", "Onset time", ... and by "axis text" is "One", "Two", "Three", "5 min", ...

Here is my closest attempt so far (thanks) (I do not care at this stage about the colors or other aesthetic details, nor about the data, just about reproducing the overall layout).

library(tidyverse)

df <- tribble(
  ~group, ~level, ~value, ~attribute,
  "g1", "some reference level", 1, "some long strip text",
  "g1", "another level", 2, "some long strip text",
  "g1", "zero units", 0, "another long strip text",
  "g1", "many units", 3, "another long strip text",
  "g1", "even more units", 4, "another long strip text",
  "g2", "some reference level", 3, "some long strip text",
  "g2", "another level", 1, "some long strip text",
  "g2", "zero units", 0, "another long strip text",
  "g2", "many units", 2, "another long strip text",
  "g2", "even more units", 3, "another long strip text"
)

ggplot(df, aes(x = value, y = factor(level))) +
  geom_col() +
  ggtitle("Title") +
  facet_grid(attribute~group, scales = "free_y", switch ="y") +
  ylab("") +
  xlab("Marginal utility") +
  theme_minimal() +
  theme(strip.placement = "outside",
        strip.text.y.left = element_text(angle = 0, face = "bold", vjust = 1, hjust = 1))

result

I would like to display "some long strip text" and "another long strip text" closer to the Y axis, on top of the axis text instead of to the left of it.

Considering the numerous discussions about this kind of situations (such as here), I have come to believe that it is currently not possible with ggplot2. Hence this feature request.

@teunbrand
Copy link
Collaborator

I do sympathise with the idea, but I think this might be better suited for an extension package that implements custom facets.
I left a comment here to not leave you entirely emptyhanded.

@teunbrand teunbrand closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants