I am having troubles defining a specific behaviour when hovering an R Plotly graphic. Here is what I would like to do : I would like the full arrow to be responsive, here it is just the tip of the arrow. I would also like, when the users hovers an arrow that this arrow stay with its opacity but the other ones have added transparency. Is it possible with plotly ? I tried some htmlwidgets onRender options but could not find a way to add the styles to all the other arrows except the one hovered.
Here is a repex :
library(ade4)
library(plotly)
library(FactoMineR)
data("decathlon")
res.pca <- dudi.pca(decathlon[, -13], scannf = FALSE, nf = 5)
res.pca.coord <- res.pca$co
res.pca.coord$Comp1init <- rep(0, nrow(res.pca.coord))
res.pca.coord$Comp2init <- rep(0, nrow(res.pca.coord))
t <- list(
family = "sans serif",
size = 14,
color = toRGB("grey50"))
plot_ly(res.pca.coord, x = ~Comp1, y = ~Comp2, text = rownames(res.pca.coord)) %>%
layout(shapes = list(
list(type = 'circle',
xref = 'x', x0 = -1, x1 = 1,
yref = 'y', y0 = -1, y1 = 1,
line = list(color = 'blue')))) %>%
add_text(textfont = t,
textposition = ifelse(res.pca.coord$Comp2 > 0 & res.pca.coord$Comp1 > 0, 'top right',
ifelse(res.pca.coord$Comp2 > 0 & res.pca.coord$Comp1 < 0, 'top left',
ifelse(res.pca.coord$Comp2 < 0 & res.pca.coord$Comp1 < 0, 'bottom left', 'bottom right')))) %>%
add_annotations( x = ~Comp1,
y = ~Comp2,
xref = "x", yref = "y",
axref = "x", ayref = "y",
text = "",
showarrow = T,
ax = ~Comp1init,
ay = ~Comp2init)


