Problem: The following code produces a plotly plot which groups data based on color and annotates text on the respective y-data-points. When interacting with the plot (in the viewer pane), the selection of e.g. only model a4
(by clicking on the line) does not work correctly as the lines disappear for all other models but the according numbers won't. Any ideas how to fix this?
library(plotly)
library(data.table)
dt <- as.data.table(mpg)
plot_ly(dt[model %in% c("a4", "passat")],
x = ~year,
y = ~displ,
color = ~model,
colors = "Set1") %>%
add_lines() %>%
add_text(y = ~displ,
text = ~displ,
textposition = "top right",
showlegend = FALSE) %>%
layout(xaxis = list(title = ""),
yaxis = list(title = "Anzahl"))
Below you can find a figure describing my problem. Once I select only a4 in the plotly chart, the passat line disappears however the numbers associated to this line remain.
Aim: How to modify the code such that not only the line disappears for a4/passat but also the associated numbers?
Appreciate your suggestions / inputs.