plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

Make ggplotly respect override.aes in guide_legend

Open talgalili opened this issue 7 years ago • 5 comments

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

image

However, this new element is ignored in ggplotly:

ggplotly(p)

image

This becomes even more critical when using a very low level of alpha, and then needing to adjust it for the legend.

Thanks.

talgalili avatar May 05 '17 22:05 talgalili

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.

DarioS avatar Aug 10 '17 01:08 DarioS

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.

antuki avatar Aug 23 '18 09:08 antuki

Is this issue still open? We have encountered the same problem, and it is frustrating. Hope somebody does something about it soon.

farshadf avatar Feb 16 '21 20:02 farshadf

After 5 years is there a solution?

ShinyFabio avatar May 10 '22 08:05 ShinyFabio

No, but I see that the package continues to be maintained and new versions released regularly. I still hold out hope.

DarioS avatar May 10 '22 11:05 DarioS

Also encountering this issue. A fix for it would be fantastic!

velicknd avatar Nov 16 '22 17:11 velicknd