Is it possible with ggvis to interactively change the variables for the x and y axes?

后端 未结 5 1074
日久生厌
日久生厌 2020-12-31 04:46

Does anyone know if it is possible to change the variables for the x and y axis interactively with ggvis? I can change the size of the data points, their position and opacit

5条回答
  •  不知归路
    2020-12-31 05:31

    You can do that like this:

    library('ggvis');
    mtcars %>% ggvis(~mpg, input_select(names(mtcars), map = as.name)) %>% layer_lines()
    # or specify by hand
    mtcars %>% ggvis(~mpg, input_select(c('wt', 'disp'), map = as.name)) %>% layer_lines()
    

    (the key is to use map and a suitable function, in this case as.name() does it but you can create your own if you have special needs)

    See documentation for input_select: http://www.rdocumentation.org/packages/ggvis/functions/input_select

    The documentation for interactivity referenced in the answer describing the shiny solution (well, I need reputation points to post more than 2 links so I can't do it but the link is given in there!) indicates that this is possible (contrary to what that answer states) but the syntax provided there doesn't work:

    prop(x = input_select(c("disp", "wt")), constant = FALSE)
    # which is to be used with props:
    props(prop(x = input_select(c("disp", "wt")), constant = FALSE))
    

    However there are hints to the use of as.name (http://ggvis.rstudio.com/properties-scales.html):

    var <- "mpg"
    prop("x", as.name(var))
    

提交回复
热议问题