teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
534 stars 32 forks source link

Possible to use expressions with guide_axis_nested()? #129

Closed gallagherman closed 5 months ago

gallagherman commented 9 months ago

I can use expressions in scale_x_discrete() normally by setting labels = expression(...), but when use guide = axis_nested, using labels doesn't work anymore, because multiple labels are needed and I think the labels are taken directly from interaction() or weave_factors(). How can we use expressions with nested axis labels? Or is there a way to pass multiple custom label elements with expressions to weave_factors?

Expressions in labels Example:

# Single category, not nested data
data <- data.frame(
  Category = factor(c("A", "B", "C", "D")),
  Value = c(10, 20, 15, 25)
)

ggplot(data, aes(x = Category, y = Value)) +
  geom_col() +

  scale_x_discrete(labels = expression(
    Category~alpha,
    Category~beta,
    Category~delta,
    Category~gamma)
  )
teunbrand commented 9 months ago

Yeah that's right, the text itself is used to parse out the different hierarchy levels, which doesn't work with expressions. I'm not planning to do any updates to guide_axis_nested(), as I'm working on something similar using functionality that now only lives in dev-ggplot2. Until that arrives, I'm afraid this isn't possible.

teunbrand commented 5 months ago

I'll close this as 'not planned' for now