teunbrand / ggh4x

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

`stat_difference()` doesn't work with categorical values #36

Closed teunbrand closed 3 years ago

teunbrand commented 3 years ago

The following works fine:

library(ggh4x)
#> Loading required package: ggplot2

df <- data.frame(
  x = c("A","B"),
  min = 1:2,
  max = 2:1
)

ggplot(df, aes(seq_along(x))) +
  stat_difference(aes(ymin = min, ymax = max))

This doesn't.

ggplot(df, aes(x)) +
  stat_difference(aes(ymin = min, ymax = max))

Created on 2021-03-26 by the reprex package (v1.0.0)

teunbrand commented 3 years ago

This should now work:

library(ggh4x)
#> Loading required package: ggplot2

df <- data.frame(
  x = c("A","B"),
  min = 1:2,
  max = 2:1
)

ggplot(df, aes(x, group = 1)) +
  stat_difference(aes(ymin = min, ymax = max))

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