r - ggvis graphic with group selection -


i want use ggvis data exploration (because familiar ggplot2), , of great help, due many groups in data sets, able select , unselect groups make different specific (data) comparisons.

set.seed(10) dat <- data.frame(x=c(1:3,1:3),y=rnorm(6),groups=factor(rep(1:2,each=3))) library(ggvis)  dat  %>% ggvis(~x, ~y) %>% layer_points(fill=~groups) # know example not work - possible somehow? dat  %>% ggvis(~x, ~y) %>% layer_points(fill=input_checkbox(~groups)) 

what want @ end, graphic can select subset of groups using radio buttons (for example). there way that? thank you!

from documentation

limitations

currently, interactive inputs can used in 2 places:

  1. as arguments transforms: layer_smooths(span = input_slider(0, 1))

  2. as properties: props(size = input_slider(10, 1000))

this means interactive inputs can modify data, not underlying plot specification. in other words, with basic interactivity there’s no way add or remove layers, or switch between different datasets. reasonable limitation because if you’re doing exploration can create new ggvis r code, or if you’re polishing plot presentation, can embed in shiny app , gain full control on plot.


for simple data exploration, 1 idea use filter():

set.seed(10) dat <- data.frame(x = c(1:5,1:5,1:5),                    y = rnorm(15), groups = factor(rep(1:5,each=3))) 

note: edited initial dataset illustrate concept more groups

library(dplyr) library(ggvis)  dat %>% ggvis(~x, ~y) %>% layer_points(fill = ~groups) 

enter image description here

you pass arguments (either manually directly in r code or radio buttons in shiny app) filter() isolate specific groups:

dat %>%    filter(groups == 1 | groups == 3) %>%    ggvis(~x, ~y) %>% layer_points(fill = ~groups) 

enter image description here


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -