teunbrand / ggh4x

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

Error: problem at render time when trying to display 10 or more variables. #5

Closed caayala closed 4 years ago

caayala commented 4 years ago

Error: a problem at render time when trying to display 10 or more cases.

When I use facet_nested with a lot of cases with geom_col I get an error. I made an example where I can display correctly 9 cases but it fails with 10.

library(tidyverse)
library(ggh4x)

df <- mtcars %>% 
  rownames_to_column('model') %>% 
  mutate(brand = str_extract(model, '(.*?) '),
         brand = coalesce(brand, model))

df %>% 
  slice(1:9) %>% 
  ggplot(aes(x = model, y = mpg)) +
  geom_col() +
  ggh4x::facet_nested(cols = vars(brand, model),
                      scales = 'free_x', space = 'free_x')


df %>% 
  slice(1:10) %>% # One aditional case.
  ggplot(aes(x = model, y = mpg)) +
  geom_col() +
  ggh4x::facet_nested(cols = vars(brand, model),
                      scales = 'free_x', space = 'free_x')
#> Error: grobs must either be a single grob or a list of grobs

Created on 2020-03-20 by the reprex package (v0.3.0)

teunbrand commented 4 years ago

Hi there,

Thanks for letting me know, I could indeed reproduce this error. I suspect this bug is the result of some recent attempt to fix #4. I'll figure out what might be done to fix this.

Best wishes

teunbrand commented 4 years ago

I think this might be fixed now. The following works:

library(tidyverse)
library(ggh4x)

df <- mtcars %>% 
  rownames_to_column('model') %>% 
  mutate(brand = str_extract(model, '(.*?) '),
         brand = coalesce(brand, model))

df %>% 
  slice(1:10) %>% # One aditional case.
  ggplot(aes(x = model, y = mpg)) +
  geom_col() +
  ggh4x::facet_nested(cols = vars(brand, model),
                      scales = 'free_x', space = 'free_x')

Created on 2020-03-23 by the reprex package (v0.3.0)

caayala commented 4 years ago

It works now in my code. Thanks!