是否可以用ggvis交互地改变x和y轴的变量? [英] Is it possible with ggvis to interactively change the variables for the x and y axes?

查看:133
本文介绍了是否可以用ggvis交互地改变x和y轴的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以用ggvis交互地改变x和y轴的变量?我可以改变数据点的大小,它们的位置和不透明度,但是如果可以允许用户从下拉列表中选择一个变量,这个变量将成为x / y轴的数据,我就无法解决这个问题。 p

解决方案 ggvis 包旨在与 dplyr ,例如总结数据。 dplyr 包也会重新导出 magrittr 管道运算符(%>%,请参阅

使用 input_select

可以更改为:





如果您不想使用

 <$ c  $ c> p < -  ggvis(iris,x = input_select(c('Petal.Width','Sepal.Length'),map = as.name))
layer_points(p,y =〜Petal。长度,填充=〜物种)


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆