【发布时间】:2019-10-02 15:15:33
【问题描述】:
我正在尝试使用 r plotly 包为我的 ggplot 小提琴图表添加一些交互性。不幸的是,每当我将绘图包裹在ggplotly 中时,我的图表就会消失。具体来说,在创建小提琴图表时,我使用draw_quantiles 参数在图表中绘制水平线。这些行在 ggplot 中正确显示,但在 plotly 输出中不存在。
以下是一个可重现的示例。第一个图表是 ggplot 包含所需的水平线。一旦 ggplot 被 ggplotly 函数包裹,水平线就会消失:
# load the libraries
library(data.table)
library(ggplot2)
library(plotly)
# create example data
DT <- data.table(x= rep(c('a', 'b', 'c'), 1000),
y = rpois(3000, lambda = c(2, 3, 5)))
# create violin chart using ggplot
p <- ggplot(DT, aes(x =x,
y = y,
fill = x)) +
geom_violin(draw_quantiles = c(0.25, 0.5, 0.75))
# wrap ggplot in plotly
ggplotly(p)
【问题讨论】: