Hi,
I have created a plot with highlight() turned on and the legend positioned at the top right of the plot (code below).
However, when I interact with the plot, the legend moves it’s position. Is there a way to prevent the legend from moving when the user interacts with the plot?
Year <- c(2014,2015,2016,2017,2018,2019,2014,2015,2016,2017,2018,2019)
Stat <- c(25, 27, 44, 43, 41, 18, 26.8, 25, 29.8, 35.1,35.2,44.8)
Level <- c("Player", "Player", "Player", "Player", "Player", "Player", "League", "League", "League", "League", "League", "League")
visData <- as.data.frame(cbind(Year, Stat, Level))
visData$Stat <- as.numeric(visData$Stat)
p<- visData %>%
highlight_key(~Year) %>%
plot_ly(x = ~Year, y = ~Stat, type = "scatter", mode = "lines+markers", marker = list(size = 8), linetype = I("solid"), color = ~Level, name = ~Level) %>%
highlight(on = "plotly_hover",
off = "plotly_doubleclick",
opacityDim = .7,
selected = attrs_selected(showlegend = FALSE)) %>%
layout(title = list(text = "Stat over Time", x = 0.1),
yaxis = list(range = c(min(visData$Stat) - (diff(range(visData$Stat))/10), max(visData$Stat) + (diff(range(visData$Stat))/7))),
showlegend = TRUE,
legend = list(orientation = 'h',
xanchor = "center",
x = 0.75,
y = 1.1))
p