Ggvis line chart with interactive x-axis range

I would like to be able

  • Layout line chart in ggvis
  • Add two interactive controls that let me set the min and max x values ​​on the chart

That sounds pretty simple - my code is:

minx = minx = input_numeric(1, 'Min x-val') maxx = input_numeric(1, 'Max x-val') data.frame(train.dt) %>% ggvis(x = ~plot_idx, y = ~val) %>% layer_lines() %>% add_axis('x') %>% scale_numeric('x', domain = c(minx, maxx), clamp = T) 

However, this does not work. I get this error message:

"Error in r [i1] - r [-length (r) :-( length (r) - lag + 1L)]: non-numeric argument to the binary operator."

If I replaced minx and maxx in the domain argument, for example. 1 and 10, my graphics are just fine (but are static). Any ideas?

Thanks!

+5
source share
1 answer

This may be helpful. Since there is no reproducible data, I decided to use an example from the CRAN manual. What you need to do is use input_slider and select min and max for the x axis. In this example, you have a two-way slider. This means that you can select / change min and max both. input_slider goes to the domain in scale_numeric .

 # Set up input_slider foo <- input_slider(1, 10, c(1, 6)) mtcars %>% ggvis(x = ~wt, y = ~mpg, stroke = ~factor(cyl)) %>% layer_lines() %>% scale_numeric("x", domain = foo, clamp = TRUE) 
+8
source

Source: https://habr.com/ru/post/1209970/


All Articles