wilkelab / ggridges

Ridgeline plots in ggplot2
https://wilkelab.org/ggridges
GNU General Public License v2.0
411 stars 31 forks source link

ggridges with plotly in flexdashboard #12

Open marcbeldata opened 6 years ago

marcbeldata commented 6 years ago

I don't know if it's a "problem" of ggridges, plotly or both, but I can't show a plotly version of a ggridge figure in a RStudio flexdashboard.

library(tidyverse)
library(forcats)
p3 <- Catalan_elections %>%
  mutate(YearFct = fct_rev(as.factor(Year))) %>%
  ggplot(aes(y = YearFct)) +
  geom_density_ridges(aes(x = Percent, fill = paste(YearFct, Option)), 
           alpha = .8, color = "white", from = 0, to = 100) +
  labs(x = "Vote (%)",
       y = "Election Year",
       title = "",
       subtitle = "Analysis unit: municipalities (n = 949)",
       caption = "Marc Belzunces (@marcbeldata) | Source: Idescat") +
  scale_y_discrete(expand = c(0.01, 0)) +
  scale_x_continuous(expand = c(0.01, 0)) +
  scale_fill_cyclical(breaks = c("1980 Indy", "1980 Unionist"),
                      labels = c(`1980 Indy` = "Indy", `1980 Unionist` = "Unionist"),
                      values = c("#ff0000", "#0000ff", "#ff8080", "#8080ff"),
                      name = "Option", guide = "legend") +
  theme_ridges(grid = FALSE)

ggplotly(p3)

unknown-2

Thanks Claus for your work.

clauswilke commented 6 years ago

Please report this also as a ggplotly bug. If there’s anything I can do to address this in ggridges I’m happy to do so but I believe custom geoms need special ggplotly support and that may be broken currently.

Also, which version of ggridges are you running? I totally reworked the drawing code in the development version and this may have broken ggplotly support.

marcbeldata commented 6 years ago

My ggridges version is the last one available on CRAN at the moment, 0.4.1.

Initially with last version of ggplot2 in CRAN, but ggplot2 recommends itself using with plotly (4.7.1 installed) the last development version, so I installed it (2.2.1.90000). It didn't worked in both.

statkclee commented 6 years ago

+1