plotly.R
plotly.R copied to clipboard
Make ggplotly respect override.aes in guide_legend
A short example:
library(ggplot2)
p <- ggplot(economics_long, aes(date, value01, colour = variable)) +
geom_line(size = .5) +
guides(colour = guide_legend(override.aes = list(size = 2)))
p
Notice the thicker lines in the legend on the right
However, this new element is ignored in ggplotly:
ggplotly(p)
This becomes even more critical when using a very low level of alpha, and then needing to adjust it for the legend.
Thanks.
Similarly, if a legend is modified with scale_colour_manual
, plotly discards most of the modifications and plots more or less the original one.
library(plotly)
dataTable <- data.frame(index = 1:10, group = rep(c("low", "undetermined", "high"), c(4, 2, 4)),
value = c(7.6, 8.8, 9.0, 9.4, 5.6, 8.3, 3.3, 4.5, 5.2, 3.0))
aPlot <- ggplot(dataTable, aes(x = index, y = value)) + geom_point(aes(colour = group))
legendStyle <- scale_colour_manual(name = "Group", breaks = c("low", "high"),
values = setNames(c("blue", "black", "red"), c("low", "undetermined", "high")),
labels = c("Low (n = 4)", "High (n = 4)"))
aPlot <- aPlot + legendStyle
aPlot # As desired.
ggplotly(aPlot) # Loss of legend modifications.
It uses the updated name, however.
Sharing this need too. Such a shame that plotly does not allow overrinding aes for legend. It would be useful, especially when you want to modify the aspect (line type, opacity) of one of the markers but not the other of the same legendgroup. I did not manage to do it, even when modifying manually the plotly object and I do not think it is possible with plotly at all... But I really hope it will be one day ! Many thanks.
Is this issue still open? We have encountered the same problem, and it is frustrating. Hope somebody does something about it soon.
After 5 years is there a solution?
No, but I see that the package continues to be maintained and new versions released regularly. I still hold out hope.
Also encountering this issue. A fix for it would be fantastic!