I took the example of geom_ribbon from this page. Result looked good with ggplot but was messed up when converting to plotly using ggplotly:
- 2 legend titles were pushed to the top.
- legend keys had unwanted trailing text
",1)" at the end.
I was wondering if it is possible to fix these issues? Thank you
library(ggplot2)
library(plotly)
set.seed(1)
x <- seq(1, 10, length = 100)
data <- data.frame(x, dnorm(x, mean = 6.5, sd = 1))
names(data) <- c("x", "new.data")
x.ribbon <- seq(1, 10, length = 20)
ribbon <- data.frame(
x.ribbon,
dnorm(x.ribbon, mean = 5, sd = 1) + .01,
dnorm(x.ribbon, mean = 5, sd = 1) - .01,
dnorm(x.ribbon, mean = 5, sd = 1)
)
names(ribbon) <- c("x.ribbon", "max", "min", "avg")
ggplot:
p <- ggplot() +
geom_ribbon(data = ribbon, aes(ymin = min, ymax = max, x = x.ribbon, fill = "lightgreen")) +
geom_line(data = ribbon, aes(x = x.ribbon, y = avg, color = "black")) +
geom_line(data = data, aes(x = x, y = new.data, color = "red")) +
xlab("x") +
ylab("density") +
scale_colour_manual(
name = "Colour",
values = c("black" = "black", "red" = "red")
) +
scale_fill_manual(
name = "Ribbon",
values = c("lightgreen" = "lightgreen")
)
p

plotly:
fig <- ggplotly(p)
fig