Skip to content

Instantly share code, notes, and snippets.

@AliciaSchep
AliciaSchep / plotly_r_update_trace_and_axis.R
Last active February 15, 2023 10:39
Use dropdown in R plotly to update both trace and axis title
## Makes plot of either mpg or hp versus wt using mtcars dataset
## Dropdown enables toggling between what variable to plot on y axis
library(plotly)
plot_ly(mtcars, x = ~wt) %>%
add_markers(y = ~mpg, name = "mpg") %>%
add_markers(y = ~hp, name = "hp", visible = FALSE) %>%
layout(
title = "Drop down menus - Update",
xaxis = list(domain = c(0.1, 1)),