# Sample data
x <- c(1, 2, 3, 4, 5)
y1 <- c(1, 3, 5, 7, 9)
y2 <- c(2, 4, 6, 8, 10)
# Line Plot with Dropdown
fig <- plot_ly() |>
add_trace(x = ~x, y = ~y1, type = 'scatter', mode = 'lines', name = 'Line 1') |>
add_trace(x = ~x, y = ~y2, type = 'scatter', mode = 'lines', name = 'Line 2') |>
layout(
title = 'Line Plot with Dropdown',
updatemenus = list(
list(
y = 0.8,
buttons = list(
list(method = "restyle",
args = list("visible", list(TRUE, FALSE)),
label = "Line 1"),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = "Line 2"),
list(method = "restyle",
args = list("visible", list(TRUE, TRUE)),
label = "Both")
)
)
)
)
fig