File: singular.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 (57 lines) | stat: -rw-r--r-- 1,494 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
46
47
48
49
50
51
52
53
54
55
56
57
#' singular.
#'
#' Use singular when you want constant x or y position.
#'
#' @export
#' @examples
#' mtcars %>% ggvis("", ~mpg) %>%
#'   layer_points() %>%
#'   scale_nominal("x") %>%
#'   add_axis("x", title = "", tick_size_major = 0)
#'
#' # OR
#' mtcars %>% ggvis("", ~mpg) %>%
#'   layer_points() %>%
#'   scale_singular("x")
#'
#' # OR, even simpler
#' mtcars %>% ggvis(singular(), ~mpg) %>% layer_points()
#'
#' # In the other direction:
#' mtcars %>% ggvis(~mpg, singular()) %>% layer_points()
#' @export
singular <- function() {
  structure("", class = "singular")
}

#' @export
rep.singular <- function(x, ...) {
  structure(NextMethod(), class = "singular")
}
#' @export
print.singular <- function(x, ...) cat("<singular>\n")

#' @export
as.data.frame.singular <- function(x, ...) {
  df <- list(x)
  attr(df, "row.names") <- .set_row_names(length(x))
  class(df) <- "data.frame"

  df
}

#' @export
vector_type.singular <- function(x) "singular"

#' @rdname singular
#' @export
#' @inheritParams scale_nominal
scale_singular <- function(vis, property, name = property, label = name,
                           points = TRUE, domain = NULL, override = NULL) {
  # Some of the arguments are ignored; they're there to provide a consistent
  # interface with other scales
  vis <- scale_nominal(vis, domain = "", property = property, name = name,
                           label = "", points = points, override = override)
  vis <- add_axis(vis, property, tick_size_major = 0)
  vis
}