Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. ## Makes plot of either mpg or hp versus wt using mtcars dataset
  2. ## Dropdown enables toggling between what variable to plot on y axis
  3.  
  4. library(plotly)
  5. plot_ly(mtcars, x = ~wt) %>%
  6. add_markers(y = ~mpg, name = "mpg") %>%
  7. add_markers(y = ~hp, name = "hp", visible = FALSE) %>%
  8. layout(
  9. title = "Drop down menus - Update",
  10. xaxis = list(domain = c(0.1, 1)),
  11. yaxis = list(title = "mpg"),
  12. showlegend = FALSE,
  13. updatemenus = list(
  14. list(
  15. y = 0.7,
  16. buttons = list(
  17. list(method = "update",
  18. args = list(list(visible = list(TRUE, FALSE)),
  19. list(yaxis = list(title = "mpg"))),
  20. label = "mpg"),
  21.  
  22. list(method = "update",
  23. args = list(list(visible = list(FALSE, TRUE)),
  24. list(yaxis = list(title = "hp"))),
  25. label = "hp")))
  26. )
  27. )
Add Comment
Please, Sign In to add comment