方面ggplotly和geom_hline的奇怪行为

时间:2019-04-25 15:58:38

标签: r ggplot2 ggplotly

我想在用geom_hline()创建的每个构面上以固定值绘制ggplotly。当我仅绘制ggplot图(带有示例数据)时,我得到正确的结果:

sawing the branch you are sitting on

但是当我想通过ggplotly对象在交互式绘图中将其打开时,某些构面将不会显示geom_hline()(注意,在ggplot2代码中,我使用了coord_flip())< / p>

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"))

您会看到某些方面没有绘制geom_hline()。这是密谋的错误还是我做错了什么?

enter image description here

0 个答案:

没有答案