ggplot2 /操作facet上的复选框

时间:2016-09-16 09:13:16

标签: r ggplot2

您是否知道在ggplot2中以交互方式选择构面的方法? 我试过操纵和复选框,没有成功......

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")
)

1 个答案:

答案 0 :(得分:1)

你可以试试,

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")
)