2

I'm trying to layer points over a boxplot. Both the points and the boxplot come from the same data source: db_gems_spend. The only difference is how they are filtered (range of dates for boxplot and a single day for points). The end goal is to add interactivity to the graph so that I will be able to select a date and immediately see how the day compares to other days by seeing where the point lands on a particular box plot.

The problem is that the points do not currently align with the box plots.

You can see it here: enter image description here

This is the code:

db_gems_spend %>%
  filter(dayofweek == "Fri") %>% # add interactivity (automate dayofweek selection)
  filter(date >= "2015-08-01") %>% # add interactivity
  ggvis(~action_type, ~count) %>%
  layer_boxplots() %>%
  add_axis("x", title = "action_type", title_offset = 50, 
           properties = axis_props(labels = list(angle = 20, align = "left", fontSize = 10))) %>%
  add_axis("y", title = "count", title_offset = 60) %>%
  add_data(db_gems_spend) %>%
  filter(date == "2015-11-04") %>% # add interactivity
  layer_points(x = ~action_type, y = ~count, fill :=  "red")

How can I get these points to align?

rene
  • 41,474
  • 78
  • 114
  • 152
Maiaia
  • 21
  • 2
  • Could you add some example data to make this question reproducible? See [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for how to create a minimal reproducible example. – aosmith Nov 10 '15 at 15:50
  • Have you seen [this issue](https://github.com/rstudio/ggvis/issues/242) on the ggvis github repository? The work around may be what you need. – aosmith Nov 10 '15 at 15:59

1 Answers1

0
db_gems_spend %>%
  ggvis(~action_type, ~(count/total_spend)) %>%
  layer_boxplots() %>%
  add_data(db_gems_spend) %>%
  layer_points(x = ~action_type, y = ~count, fill := "red", 
    prop("x", ~action_type, scale = "xcenter"))

Thanks aosmith, the solution on github was what I was looking for. It turns out ggvis will align layer_points to the left of layer_boxplots if the values are categorical and not numerical unless you specify the last line of code from above.

Maiaia
  • 21
  • 2