0

I am trying to use a dropdown menu to plot a subsample of a dataset using the dropdown menu from plotly in R.

This is what I have so far (based on this answer) without sucess:

library(data.table)
library(ggplot2)
library(plotly)

X <- data.table(xcoord = 1:10, ycoord = 1:10)
Z <- X[xcoord < 5]

gg <- ggplot(X, aes(x = xcoord, y = ycoord)) + geom_point()

ggplotly(gg) %>%
  layout(updatemenus = list(
    list(buttons = list(
      list(method = "restyle",
           args = list(list("x", list(X$xcoord)),
                       list("y", list(X$xcoord))),
           label = "X"),
      list(method = "restyle",
           args = list(list("x", list(Z$xcoord)),
                       list("y", list(Z$ycoord))),
           label = "Z")
    ))
  ))

1 Answer 1

1

Found the solution: had to use named lists instead.

ggplotly(gg) %>%
  layout(updatemenus = list(
    list(buttons = list(
      list(method = "restyle",
           args = list(list(x = list(X$xcoord)),
                       list(y = list(X$xcoord))),
           label = "X"),
      list(method = "restyle",
           args = list(list(x = list(Z$xcoord)),
                       list(y = list(Z$ycoord))),
           label = "Z")
    ))
  ))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.