File: scale_edge_shape.R

package info (click to toggle)
r-cran-ggraph 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,648 kB
  • sloc: cpp: 1,219; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#' Edge shape scales
#'
#' This set of scales defines new shape scales for edge geoms equivalent to the
#' ones already defined by ggplot2. See [ggplot2::scale_shape()] for
#' more information. The different geoms will know whether to use edge scales or
#' the standard scales so it is not necessary to write `edge_shape` in
#' the call to the geom - just use `shape`.
#'
#' @param guide Guide to use for this scale.
#'
#' @return A ggproto object inheriting from `Scale`
#'
#' @family scale_edge_*
#'
#' @name scale_edge_shape
#' @rdname scale_edge_shape
#'
NULL

#' @rdname scale_edge_shape
#'
#' @inheritParams ggplot2::scale_shape
#'
#' @export
scale_edge_shape <- function(..., solid = TRUE) {
  sc <- scale_shape(..., solid = solid)
  sc$aesthetics <- 'edge_shape'
  sc
}
#' @rdname scale_edge_shape
#'
#' @export
scale_edge_shape_discrete <- scale_edge_shape
#' @rdname scale_edge_shape
#'
#' @export
scale_edge_shape_continuous <- function(...) {
  cli::cli_abort(c(
    "A continuous variable cannot be mapped to the {.field edge_shape} aesthetic",
    "i" = "choose a different aesthetic or use {.fn scale_edge_shape_binned}"
  ))
}
#' @rdname scale_edge_shape
#'
#' @export
scale_edge_shape_binned <- function(..., solid = TRUE) {
  sc <- scale_shape_binned(..., solid = solid)
  sc$aesthetics <- 'edge_shape'
  sc
}
#' @rdname scale_edge_shape
#'
#' @inheritParams ggplot2::scale_shape_manual
#'
#' @export
scale_edge_shape_manual <- function(..., values, breaks = waiver(), na.value = NA) {
  sc <- scale_shape_manual(..., values = values, breaks = breaks, na.value = na.value)
  sc$aesthetics <- 'edge_shape'
  sc
}
#' @rdname scale_edge_shape
#'
#' @inheritParams ggplot2::scale_shape_identity
#'
#' @importFrom scales identity_pal
#' @export
scale_edge_shape_identity <- function(..., guide = 'none') {
  sc <- scale_shape_identity(..., guide = guide)
  sc$aesthetics <- 'edge_shape'
  sc
}