plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Does not respect space = "free" in facet_grid

Open stanstrup opened this issue 7 years ago • 11 comments

mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point()
p <- mt + facet_grid(. ~ cyl, scales = "free", space = "free")

p image

ggplotly(p) image

stanstrup avatar Mar 22 '17 14:03 stanstrup

Hi have a workaround using plotly's subplot function. Still needs further tuning, so please keep adding.

library(plotly)
library(tidyverse)

#define plot yaxis limits 
limits <- mtcars %>%
  summarise(max = ceiling(max(wt*1.1)),
            min = floor(min(wt*0.9)))

#define width of subplots by finding the absolut range of each "facet"
plot_width<- mtcars %>%
  group_by(cyl) %>%
  summarise(range = range(mpg)[2]-range(mpg)[1]) %>%
  ungroup() %>%
  mutate(width_pct = range/sum(range))


#define a list of ggplot and feed it in the subplot function with the calculated limits
mtcars %>%
  split(.$cyl) %>%
  map(function(x) {
    ggplot(data=x,aes(mpg,wt)) + geom_point(size=2)+
      facet_grid(.~cyl) + ylim(c(limits$min,limits$max))
  }) %>%
  subplot(margin = 0.005, shareY = T,widths = plot_width$width_pct) 

image

Mschwindi avatar Apr 09 '20 12:04 Mschwindi

Issue still there. Any chance this will be fixed ? We want to use ggplot free scale feature in combination with plotly tooltip.
Thanks!

choogland avatar Apr 22 '20 12:04 choogland

Issue is still present. Would be nice to see this fixed. Thank you!

Thonnard avatar Jul 28 '21 13:07 Thonnard

Same issue here.

Zhenglei-BCS avatar Oct 20 '21 17:10 Zhenglei-BCS

Would be really helpful if this issue could be fixed.

federicotallis avatar Jan 26 '22 01:01 federicotallis

same here :<

xinyixinyijiang avatar May 12 '22 17:05 xinyixinyijiang

Same issue

fuhred avatar Jun 14 '22 01:06 fuhred

Same issue :/

wbelzak avatar Aug 19 '22 17:08 wbelzak

same issue here

MaggieLuCB avatar Mar 19 '23 05:03 MaggieLuCB

Same issue here

xueyuanj avatar Jun 09 '23 18:06 xueyuanj

Same issue

mariecrane avatar Oct 31 '23 16:10 mariecrane