Show all values on tooltips when hover on plot

Viewed 452

I want to receive the result like on the plot in the end of the page on that link https://fabioconcina.github.io/plotly-r-multiple-lines.html

Currently I can see only the values of the line on which I hover. Besides that is necessary for me to use lapply to add multiple traces on chart.

iris <- data.table(iris)
iris <- iris[, .(Petal.Length, Petal.Width, Species)]
iris <- dcast(iris, Petal.Width~Species, value.var = "Petal.Length")
iris <- data.frame(iris)
categories_column <- "Petal.Width"
measure_columns <- names(iris)[-1]

p <- plot_ly()

invisible(lapply(measure_columns, function(column) {
  p <<- add_lines(p, x = iris[, categories_column], y = iris[, column], 
                  name = column, type = 'scatter', mode = 'lines', 
                  visible = TRUE)
}))

p

EDIT

So when it is necessary to show all data when hover on plot you need to add

layout(hovermode = 'x')
0 Answers
Related