I would like to display the x- and y-axis cursos coordinates at all times and wherever on the plot.
This is what I am looking for:
This is what I have tried, without success:
library(magrittr)
library(ggplot2)
library(plotly)
X <- data.frame(xcoord = -5:5, ycoord = -5:5)
gg <- ggplot(X, aes(xcoord, ycoord)) + geom_point() + labs(x = "", y = "")
ggplotly(gg) %>%
add_trace(type = "bar",
x = ~xcoord, y = 0,
hoverinfo = 'text',
text = ~paste("X:", xcoord),
yaxis = "y", opacity = 0,
showlegend = FALSE,
marker = list(color = "#ffffff")) %>%
layout(hovermode = "x")
Edit
I do not have access to a shiny server.