【发布时间】:2021-12-07 16:13:57
【问题描述】:
我正在尝试确定如何确保在 ggplot2 中的 geom_rect 的 fill 在包裹在 plotly::ggplotly() 中后得到尊重。
例子:
我首先创建一个data.frame,其中包含我将用于生成绘图的值。
library(ggplot2)
library(plotly)
dat <- data.frame(provider = rep(c('a','b','c'),2),
category = c(rep(c('Inpatient'),3),rep(c('Outpatient'),3)),
revenue = runif(6,100,500),
background_col = rep(c('red','green','blue'),2)
)
仅使用ggplot 会尊重geom_rect 上的背景面板颜色
ggplot(dat,aes(x=category,y=revenue)) +
geom_rect(data = dat,aes(fill = background_col),xmin = -Inf,xmax = Inf,
ymin = -Inf,ymax = Inf,alpha = 0.1) +
geom_bar(stat = 'identity') +
facet_grid(~provider)
但是,当我用ggplotly 包裹它时,那些背景颜色消失了。
ggplotly(ggplot(dat,aes(x=category,y=revenue)) +
geom_rect(data = dat,aes(fill = background_col),xmin = -Inf,xmax = Inf,
ymin = -Inf,ymax = Inf,alpha = 0.1) +
geom_bar(stat = 'identity') +
facet_grid(~provider))
有什么想法吗?我对plotly 的所有复杂性并不是非常熟悉,因此任何见解都会有所帮助!
【问题讨论】:
-
stackoverflow.com/questions/51368587/… 的可能重复项。我猜这是情节中的一个错误
-
是的,好主意。确认错误:github.com/plotly/plotly.R/issues/1559