In a graph produced with R and plotly, I’m fine with the legend in its default position, but the margin is automatically moved to leave the legend outside of the graph and the graph area is reduced.
library(plotly)
x <- 1:100
y1 <- rnorm(100)+10/x
y2 <- rnorm(100)+10/x
p <- plot_ly()
p <- add_lines(p, x=~x, y=~y1, name="very long name 1")
p <- add_lines(p, x=~x, y=~y2, name="even longer name 2")
p
I would leave the legend where it is while leaving the graph use all the area, that is, overlaying the legend on the graph. I know I can specify the absolute position of the legend inside the graph, but I assume there should be a simpler way just to tell plotly not to reduce the margins to accommodate the legend outside. From the documentation it seems that automargin=FALSE should do that, but it didn’t seem to work for me, but maybe I’m just putting it in the wrong place.