When I convert a ggplot
with two separate legends to plotly
(using ggplotly
), the two legends merge. Does anyone know how to prevent this?
library(tidyverse)
library(plotly)
df <- data.frame(date =
as.Date(c("01/01/1998", "10/01/1998", "15/01/1998",
"25/01/1998", "01/02/1998", "12/02/1998", "20/02/1998"), "%d/%m/%Y"),
date2 = as.Date(c(NA, "10/01/1998", NA,
NA, NA, NA, NA), "%d/%m/%Y"),
counts = c(12, 10, 2, 24, 15, 1, 14),
yes_no = c("yes", "yes", "yes", "no", "no", "no", "no"))
gg <- ggplot(df, aes(x = date, y = counts)) +
geom_line() +
geom_ribbon(aes(ymin = 0, ymax = counts, fill = yes_no), color = NA, alpha = 0.5) +
ggplot2::scale_fill_brewer(name = "status 1", palette = "Accent") +
geom_vline(mapping = aes(xintercept = as.numeric(date2), col = "mystatistic")) +
scale_color_manual(name = "statistics", values = c("mystatistic" = "red"))
gg
which produces two legends:
but when I convert to plotly
:
ggplotly(gg)
it returns one legend with second legend title missing:
This link is useful to remove the parenthesis and comma from the current plot but that's not the fix I am looking for.
thanks