File: subvis.R

package info (click to toggle)
r-cran-ggvis 0.4.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,716 kB
  • sloc: sh: 25; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Create a subvisualisation.
#'
#' @keywords internal
#' @examples
#' # Examples don't work yet
#' \dontrun{
#' library(dplyr, warn.conflicts = FALSE)
#'
#' small <- nasaweather::atmos %>%
#'   filter(lat <= -11.217391, long <= -106.287, year == 1995) %>%
#'   group_by(long, lat)
#' small %>%
#'   ggvis(~long, ~lat) %>%
#'   layer_points()
#'
#' small %>%
#'   ggvis(~long, ~lat) %>%
#'   subvis(width := 100, height := 100, stroke := "red") %>%
#'     layer_points(~month, ~ozone)
#'
#' small %>%
#'   ggvis(~long, ~lat) %>%
#'   subvis(width := 100, height := 100, stroke := "red") %>%
#'     layer_points(~month, ~ozone) %>%
#'     add_axis("x", ticks = 3) %>%
#'     add_axis("y", ticks = 3)
#' }
subvis <- function(vis, ..., data = NULL, width = NULL, height = NULL) {
  # Very similar to add_mark, but changes to cur_data and cur_props are
  # persistent, we use the special mark_group() and update cur_vis
  vis <- add_data(vis, data, deparse2(substitute(data)))
  vis <- add_props(vis, .props = props(...))
  vis <- register_scales_from_props(vis, cur_props(vis))

  new_mark <- mark_group(vis$cur_props, vis$cur_data)
  vis$marks <- append(vis$marks, list(new_mark))

  # Parent properties control apperance mark_group, and are not
  # inherited by child
  vis$cur_props <- NULL
  vis$cur_vis <- c(vis$cur_vis, length(vis$marks))
  vis

  vis
}