Attempting to use Scatterplot Dropdowns for a series of many Variables

Hello all,

I have a dataframe that is 36 observations of 23 variables, and I am trying to create a plotly figure that allows me to use dropdowns to compare any variable against any other variable in that dataframe to explore potential connections.

The example given for this uses a method like the one I’ve pasted below, but I run into two problems when I try to tinker with it for my own purposes. Firstly, I can’t figure out a way to be able to create a dropdown of the x-axis, so I can modify that too (even when I leave x = ~wt out of the first plot_ly function line). Secondly, I want to be able to make all of my variables be able to be placed on either axis, which, using my current (failed) attempts, would be several hundred lines of code for what I know should be much easier. i.e I want to be able to plot wt vs mpg and mpg vs hp and hp vs wt and…etc.

Any thoughts?

Thank you for your time, and apologies if I don’t do a great job of using example data here, or poorly format this problem.

plot_ly(mtcars, x = ~wt) %>%
  add_markers(y = ~mpg, name = "mpg") %>%
  add_markers(y = ~hp, name = "hp", visible = FALSE) %>%
    title = "Drop down menus - Update",
    xaxis = list(domain = c(0.1, 1)),
    yaxis = list(title = "mpg"),
    showlegend = FALSE,
    updatemenus = 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")))