ggvis 是否可以交互地更改 x 和 y 轴的变量? [英] Is it possible with ggvis to interactively change the variables for the x and y axes?
问题描述
有谁知道是否可以使用 ggvis 交互地更改 x 和 y 轴的变量?我可以更改数据点的大小、它们的位置和不透明度,但我无法确定是否可以允许用户从下拉列表中选择一个变量,该变量将成为 x/y 轴的数据.>
ggvis
包旨在与 dplyr
结合使用,例如来总结数据.dplyr
包还重新导出了 magrittr
管道运算符(%>%
,请参阅
使用 input_select
这可以更改为:
如果您不想使用 dplyr
/magrittr
,它看起来像这样:
p <- ggvis(iris, x = input_select(c('Petal.Width', 'Sepal.Length'), map = as.name))layer_points(p, y = ~Petal.Length, fill=~Species)
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 opacity, but I can't work out if its possible to allow the user to select a variable from a dropdown that will become the data for the x/y axis.
The ggvis
package was designed to be used in conjunction with dplyr
, e.g. to summarise data. The dplyr
package also re-exports the magrittr
pipe operator (%>%
, see README.md), which makes working with ggvis
' implementation of The Grammar of Graphics particularly intuitive (see also this article by the author of these packages, Hadley Wickham).
Below I'll illustrate how to use the input_select()
function to change the x
of a model and leave the y
constant.
First we need to load the two required libraries:
library(dplyr)
library(ggvis)
Now we can plot a data.frame
(I'm using the build-in pre-loaded iris
):
iris %>%
ggvis(x = input_select(c('Petal.Width', 'Sepal.Length'), map = as.name)) %>%
layer_points(y = ~Petal.Length, fill = ~Species)
The output is:
using the input_select
this can be changed to:
If you prefer not to use dplyr
/ magrittr
it would look like this:
p <- ggvis(iris, x = input_select(c('Petal.Width', 'Sepal.Length'), map = as.name))
layer_points(p, y = ~Petal.Length, fill=~Species)
这篇关于ggvis 是否可以交互地更改 x 和 y 轴的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!