Dynamic group selection in ggvis

So, I'm trying to visualize the following data using ggvis, because I want to be able to look at different clients and a different combination of clients. I would like to use a line graph, and then select two or three and simultaneously view them on the plot. The problem is that I canโ€™t say for sure which ones Iโ€™m viewing. Every time I try something a little different; I am facing something else. See below, the data is calledm3

customer   score    model
a          0.437    1
a          0.471    2
a          0.036    3
b          0.455    1
b          0.371    2
b          0.462    3
c          0.280    1
c          0.042    2
c          0.279    3
d          0.282    1
d          0.470    2
d          0.246    3
e          0.469    1
e          0.500    2
e          0.303    3
f          0.290    1
f          0.387    2
f          0.161    3
g          0.075    1
g          0.111    2
g          0.116    3

Attempt 1: With this, I can see the lines, but I get a strange warning if I select two clients, and I canโ€™t say which lines belong to whom. He also drops the second observation modelfor both clients.

m3 %>% ggvis(x=~factor(model),y=~score)%>% 
  filter(customer == eval(input_select(choices = as.character(m3$customer),multiple=TRUE,label='Select which Domains to view'))) %>% 
  layer_lines()

Plot 1

2: , . . - 'a' 'c'.

m3 %>% ggvis(x=~factor(model),y=~score)%>% 
  filter(customer == eval(input_select(choices = as.character(m3$customer),multiple=TRUE,label='Select which Domains to view'))) %>% 
  layer_lines() %>% layer_text(text:= ~customer)

Plot 2

Section 2: View 2

. add_legend layer_lines stroke, , , , , , . ggvis? - ?

+4
1

:

m3 %>% 
      #group by customer in order to separate them
      group_by(customer) %>% 
      #the normal ggvis call
      ggvis(x=~factor(model),y=~score) %>%
      #filter in the same way that you did 
      #but add unique in order to pick one customer 
      #also make sure you use %in% instead of == in order to 
      #select multiple customers. == was the reason for the warning you received
      #in your code
      filter(customer %in% eval(input_select(choices = unique(as.character(m3$customer)),
                                             multiple=TRUE,
                                             label='Select which Domains to view'))) %>%
      #add layer_paths with the stroke argument in order for
      #different customers to have different colours (and a legend)
      layer_paths(stroke = ~customer)

:

enter image description here

, , (b, c d). . layer_paths layer_lines, , .

+3

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


All Articles