Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## 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)),
- yaxis = list(title = "mpg"),
- showlegend = FALSE,
- updatemenus = list(
- list(
- y = 0.7,
- buttons = list(
- list(method = "update",
- args = list(list(visible = list(TRUE, FALSE)),
- list(yaxis = list(title = "mpg"))),
- label = "mpg"),
- list(method = "update",
- args = list(list(visible = list(FALSE, TRUE)),
- list(yaxis = list(title = "hp"))),
- label = "hp")))
- )
- )
Add Comment
Please, Sign In to add comment