teunbrand / ggh4x

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

truncated axes cutoffs can't be set directly for discrete scales #39

Closed teunbrand closed 3 years ago

teunbrand commented 3 years ago
library(ggplot2)
library(ggh4x)

ggplot(mpg, aes(class, hwy)) +
  geom_boxplot() +
  guides(x = guide_axis_truncated(
    trunc_lower = "compact",
    trunc_upper = "subcompact"
  )) +
  theme(axis.line = element_line(colour = "black"))
#> Error in scale$scale$trans$transform(trunc): attempt to apply non-function

Created on 2021-04-19 by the reprex package (v1.0.0)

teunbrand commented 3 years ago

This now works:

library(ggplot2)
library(ggh4x)

ggplot(mpg, aes(class, hwy)) +
  geom_boxplot() +
  guides(x = guide_axis_truncated(
    trunc_lower = "compact",
    trunc_upper = "subcompact"
  )) +
  theme(axis.line = element_line(colour = "black"))

Created on 2021-06-21 by the reprex package (v1.0.0)