ggvis多个变量选项

时间:2016-01-14 15:22:50

标签: r ggvis

我们假设以下数据框

mydata = data.frame(
date = seq.Date(from = as.Date('2012-01-01'),to = as.Date('2015-6-01'), 'months'),
name = 'a',
var1 = sample(seq(from = 0, to = 1000, by = 1), size = 42, replace = TRUE),
var2 = sample(seq(from = 0, to = 1000, by = 1), size = 42, replace = TRUE),
var3 = sample(seq(from = 0, to = 1000, by = 1), size = 42, replace = TRUE),
stringsAsFactors = FALSE)

在我当前的数据集中,我有更多的名字,我选择哪个ggvis应该用选择列表打印,我想知道是否可以选择哪些列代表(目前我只代表一个代表= ~var1)

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。我使用gather()将我的数据转换为长格式,将我的所有列转换为两列(变量和值),然后我应用了这样的过滤器:

ggvis(x = ~as.character.Date(date), y = ~value)%>%
  filter(variable %in% eval(input_select(choices = as.character(long.df$var))))
  )%>%
  layer_lines(stroke = ~nombre_centro)