hafen / trelliscopejs

TrelliscopeJS R Package
https://hafen.github.io/trelliscopejs
Other
263 stars 37 forks source link

Layered ggplot object not faceting correctly #74

Open pete900 opened 5 years ago

pete900 commented 5 years ago

I'm using facet_trelliscope from the trelliscopejs package for data visualisation. It works fine when my ggplot has one layer. But if I introduce a second layer it doesn't facet correctly. Example:

# Load packages
library(tidyverse)
library(trelliscopejs)    

# Basic stat summary table using iris
stat_sum <-
  iris %>%
  group_by(Species) %>%
  summarise(l_mean = mean(Sepal.Length))

#Standard ggplot with facet_wrap 
ggplot(iris, aes(Sepal.Length, Petal.Width)) +
  geom_point() +
  geom_vline(data = stat_sum, aes(xintercept = l_mean)) +
  facet_wrap(~Species)

# Use facet_trelliscope. Data from stat_sum does not facet
ggplot(iris, aes(Sepal.Length, Petal.Width)) +
  geom_point() +
  geom_vline(data = stat_sum, aes(xintercept = l_mean)) +
  facet_trelliscope(~Species) 

See this question on stack:

https://stackoverflow.com/questions/54324888/how-to-use-facet-trelliscope-when-ggplot-has-multiple-layers

hafen commented 5 years ago

Thanks for the report. Multiple layers work just fine with trelliscopejs except for this special case where the layers have their own data. I have fixed this in a separate branch but haven't done extensive testing to make sure it doesn't break anything else. Please try it out and see if it works for you:

devtools::install_github("hafen/trelliscopejs", ref = "fix-layer-specific-data")
pete900 commented 5 years ago

Yes that works,. Many thanks, this package is great.