Jam Jam - 5 months ago 67
R Question

R interactive plot: show vertical line on hover

I have been looking around for a way to draw a vertical line along the x-axis when hovering over points in a plot using R. It does not really matter which package it is, whether it is plotly, ggvis, rCharts, googleVis or any other for that matter, but I would rather use one of the these mentioned ones if possible.

Here is an example of what I would like to have.


A partial answer (can't comment)... Plotly has type "scattergl" which draws a horizontal and vertical line on hover.



sdate <- as.Date("2015-01-01", format = "%Y-%m-%d")
timedf <- data.frame(Date = seq.Date(sdate, by="month", length.out=12),
                         Amount = runif(12, 0, 100))
# Plotly plot
plot_ly(timedf, x=Date, y=Amount, type="scattergl")

Output enter image description here