thomasp85 / ggforce

Accelerating ggplot2
https://ggforce.data-imaginist.com
Other
916 stars 106 forks source link

Error in `facet_zoom()` while using `theme_set()` and `ggthemes` #282

Closed matiasandina closed 9 months ago

matiasandina commented 2 years ago

I was trying to plot something using facet_zoom() with xlim to specify the region and was getting "subscript too long..." error. I tried the vanilla example from the docs and I got the same error.

library(ggplot2)
library(ggforce)
theme_set(ggthemes::theme_base() + theme(plot.background = element_rect(color=NA)))
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() +
  facet_zoom(xlim = c(2, 4))
#> Warning in rep(colour, length.out = length(alpha)): 'x' is NULL so the result
#> will be NULL
#> Error in `[<-`(`*tmp*`, !is.na(alpha), 4, value = alpha[!is.na(alpha)]): (subscript) logical subscript too long

I knew that the vanilla example had to work, so I tried it using theme_gray() and it woks as expected.

# Works with theme gray()
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() + 
  theme_gray() +
  facet_zoom(xlim = c(2, 4)) 

Same for theme_bw()

# Works with theme bw()
ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +
  geom_point() + 
  theme_bw() +
  facet_zoom(xlim = c(2, 4)) 

Not sure this is a ggforce or ggthemes issue to be honest, so this might not be the best place to put it.

Created on 2022-09-26 by the reprex package (v2.0.1)

thomasp85 commented 9 months ago

This seems to be fixed. Feel free to reopen if it still causes an issue