plotly.R
plotly.R copied to clipboard
Only a single geom_pointrange() layer showing when using ggplotly()
I am trying to use ggploty to show a ggplot with two pointrange layers. This works in ggplot but not when I use ggplotly. I am not sure if this is possible to do?
# Create some dummy data
``` r
dat<-dplyr::tibble("kvotealtternativ"=c(15,30,45),
"prognose"=c(68.9,60.6,52.4),
"lower50" =c(62,54,45),
"lower75"=c(56.7,48.8,40.9),
"upper50"=c(76,66,58),
"upper75"=c(82.2,73.5,64.9))
# Create the ggplot with two layers - 75% CI and 50% CI
p=dat |>
ggplot2::ggplot()+
ggplot2::geom_pointrange(mapping=ggplot2::aes(x=kvotealtternativ, y=prognose, ymin=upper75, ymax=lower75), fatten=1, size=3, color="darkred")+
ggplot2::geom_pointrange(mapping=ggplot2::aes(x=kvotealtternativ, y=prognose, ymin=upper50, ymax=lower50), fatten=1, size=3, color="darkorange")+
ggplot2::geom_point(ggplot2::aes(kvotealtternativ,prognose), colour="black", size=6)+
ggplot2::labs(x="Uttak", y="Prognose")+
ggplot2::geom_hline(yintercept=65, linetype=2)+
ggplot2::theme_classic()+
ggplot2::theme(axis.text.x = ggplot2::element_text(color = "grey20", size = 15, face = "plain"),
axis.text.y = ggplot2::element_text(color = "grey20", size = 15, face = "plain"),
axis.title.x = ggplot2::element_text(color = "grey20", size = 20, face = "plain"),
axis.title.y = ggplot2::element_text(color = "grey20", size = 20, face = "plain"))
# This is the desired plot
p
# But when I use ggplotly the 75% layer is not displayed
plotly::ggplotly(p, tooltip="none")
Created on 2023-10-19 with reprex v2.0.2