Skip to content

Instantly share code, notes, and snippets.

@allatambov
Last active May 18, 2021 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allatambov/f2dc41154b150f51455a9500c8258640 to your computer and use it in GitHub Desktop.
Save allatambov/f2dc41154b150f51455a9500c8258640 to your computer and use it in GitHub Desktop.
# choose color
scat <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length,
type = "scatter", mode = "markers",
marker = list(color = "blue"))
scat <- scat %>% layout(title = list(text = "<b>Iris Data</b>"),
updatemenus = list(list(x = -0.5,
y = 4,
buttons = list(
list(method = "restyle",
args = list("marker.color", "violet"),
label = "Violet"),
list(method = "restyle",
args = list("marker.color", "yellow"),
label = "Yellow"),
list(method = "restyle",
args = list("marker.color", "blue"))
))))
scat
# one menu
base <- plot_ly(data = iris, x = ~Sepal.Length)
base <- base %>% add_trace(data = iris_setosa, type = "histogram",
name = "Setosa", visible = TRUE)
base <- base %>% add_trace(data = iris_color, type = "histogram",
name = "Versicolor", visible = FALSE)
base <- base %>% add_trace(data = iris_virgin, type = "histogram",
name = "Virginica", visible = FALSE)
base <- base %>% layout(updatemenus = list(
list(
x = -0.5,
y = 1,
buttons = list(
list(label = "Setosa",
method = "restyle",
args = list("visible", c(TRUE, FALSE, FALSE))),
list(label = "Versicolor",
method = "restyle",
args = list("visible", c(FALSE, TRUE, FALSE))),
list(label = "Virginica",
method = "restyle",
args = list("visible", c(FALSE, FALSE, TRUE)))
)
)
))
base
# two menus
base <- plot_ly(data = iris, x = ~Sepal.Length)
base <- base %>% add_trace(data = iris_setosa, type = "histogram",
name = "Setosa", visible = TRUE)
base <- base %>% add_trace(data = iris_color, type = "histogram",
name = "Versicolor", visible = FALSE)
base <- base %>% add_trace(data = iris_virgin, type = "histogram",
name = "Virginica", visible = FALSE)
base <- base %>% add_trace(data = iris_setosa, type = "box",
name = "Setosa Boxplot", visible = FALSE)
base <- base %>% add_trace(data = iris_color, type = "box",
name = "Versicolor Boxplot", visible = FALSE)
base <- base %>% add_trace(data = iris_virgin, type = "box",
name = "Virginica Boxplot", visible = FALSE)
base <- base %>% layout(updatemenus = list(
list(
x = -0.5,
y = 1,
buttons = list(
list(label = "Setosa",
method = "restyle",
args = list("visible", c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE))),
list(label = "Versicolor",
method = "restyle",
args = list("visible", c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE))),
list(label = "Virginica",
method = "restyle",
args = list("visible", c(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)))
)
),
list(
x = -0.5,
y = 0.8,
buttons = list(
list(label = "Histogram",
method = "restyle",
args = list("type", "histogram")),
list(label = "Boxplot",
method = "restyle",
args = list("type", "box"))
)
)
))
base
# three menu
base <- base %>% layout(updatemenus = list(
list(
x = -0.5,
y = 1,
buttons = list(
list(label = "Setosa",
method = "restyle",
args = list("visible", c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE))),
list(label = "Versicolor",
method = "restyle",
args = list("visible", c(FALSE, TRUE, FALSE, FALSE, FALSE, FALSE))),
list(label = "Virginica",
method = "restyle",
args = list("visible", c(FALSE, FALSE, TRUE, FALSE, FALSE, FALSE)))
)
),
list(
x = -0.5,
y = 0.8,
buttons = list(
list(label = "Histogram",
method = "restyle",
args = list("type", "histogram")),
list(label = "Boxplot",
method = "restyle",
args = list("type", "box"))
)
),
list(x = -0.5,
y = 0.6,
buttons = list(
list(label = "Granny's apples",
method = "restyle",
args = list("marker.color", "#A8E4A0")),
list(label = "Gray window",
method = "restyle",
args = list("marker.color", "#9DA1AA")),
list(label = "Toad in love",
method = "restyle",
args = list("marker.color", "#3CAA3C"))
)
))
)
base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment