user2165907
user2165907

Reputation: 1451

ggplot2/manipulate checkbox on facets

Would you know a way to interactively select facets in ggplot2? I tried manipulate and checkbox, without success...

library(ggplot2)
library(manipulate)

manipulate(
  ggplot(subset(iris, Species %in% c(cb1, cb2, cb3)), aes(x = Petal.Width, y = Petal.Length)) +
    facet_grid(. ~ Species) +
    geom_point(),
  cb1 = checkbox(TRUE, "setosa"),
  cb2 = checkbox(TRUE, "versicolor"),
  cb3 = checkbox(TRUE, "virginica")
)

Upvotes: 0

Views: 75

Answers (1)

R_SOF
R_SOF

Reputation: 288

You could try,

vector=c("setosa","versicolor","virginica")

manipulate(ggplot(subset(iris, Species %in% vector[c(cb1, cb2, cb3)]), aes(x = Petal.Width, y = Petal.Length)) +
    facet_grid(. ~ Species) +
    geom_point(),
    cb1 = checkbox(TRUE, "setosa"),
    cb2 = checkbox(TRUE, "versicolor"),
    cb3 = checkbox(TRUE, "virginica")
)

Upvotes: 1

Related Questions