I want to plot geom_hline() on a fixed value in each facet I create with ggplotly. When I only plot the ggplot plot (with example data) I get the right results:

enter image description here

But when I want to turn it in a interactive plot through a ggplotly object some facets won't show the geom_hline()(notice in the ggplot2 code I used a coord_flip())

library(tidyverse)
library(ggbeeswarm)
library(ggplotly)

example_df <- structure(list(dbc = c("040201021", "069899282", "129999093", 
"131999277", "159999033", "219799011", "990003025", "991900003", 
"040201021", "069899282", "129999093", "131999277", "159999033", 
"219799011", "990003025", "991900003"), kind = c("max", "max", 
"max", "max", "max", "max", "max", "max", "min", "min", "min", 
"min", "min", "min", "min", "min"), price = c(2518, 831, 2027, 
829, 879, 609, 774, 709, 81, 20, 112, 40, 31, 39, 2, 41)), row.names = c(NA, 
-16L), class = c("tbl_df", "tbl", "data.frame"))

plot <- example_df %>%  
  ggplot(aes(0 , price, label = kind)) +
  geom_hline(yintercept = 385) +
  geom_quasirandom(shape = 21,
             color = pointer_palette("paars"),
             fill = "white",
             size = 2) +
  facet_wrap(~ dbc,
             scales = "free",
             ncol = 2) +
  coord_flip() +
  theme(axis.text.y = element_blank()) +
  labs(x = NULL,
       y = "prijsafspraak in euro's")

ggplotly(plot, tooltip = c("label", "price"))

You see that some facets don't have the geom_hline() plotted. Is this a bug in plotly or am I doing something wrong?

enter image description here

0 Answers