File: scale_edge_size.R

package info (click to toggle)
r-cran-ggraph 2.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,832 kB
  • sloc: cpp: 1,630; makefile: 2
file content (116 lines) | stat: -rw-r--r-- 3,818 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#' Edge size scales
#'
#' This set of scales defines new size scales for edge geoms equivalent to the
#' ones already defined by ggplot2. See [ggplot2::scale_size()] 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_size` in
#' the call to the geom - just use `size`.
#'
#' @note In ggplot2 size conflates both line width and point size into one
#' scale. In ggraph there is also a width scale ([scale_edge_width()])
#' that is used for linewidth. As edges are often represented by lines the width
#' scale is the most common.
#'
#' @return A ggproto object inheriting from `Scale`
#'
#' @family scale_edge_*
#'
#' @name scale_edge_size
#' @rdname scale_edge_size
#'
NULL

#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_continuous
#'
#' @export
scale_edge_size_continuous <- function(name = waiver(), breaks = waiver(), labels = waiver(),
                                       limits = NULL, range = c(1, 6),
                                       trans = "identity", guide = "legend") {
  sc <- scale_size_continuous(name = name, breaks = breaks, labels = labels, limits = limits,
                              range = range, trans = trans, guide = guide)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_radius
#'
#' @export
scale_edge_radius <- function(name = waiver(), breaks = waiver(), labels = waiver(),
                              limits = NULL, range = c(1, 6),
                              trans = "identity", guide = "legend") {
  sc <- scale_radius(name = name, breaks = breaks, labels = labels, limits = limits,
                     range = range, trans = trans, guide = guide)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @export
scale_edge_size <- scale_edge_size_continuous
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_discrete
#' @export
scale_edge_size_discrete <- function(...) {
  cli::cli_warn("Using {.field edge_size} for a discrete variable is not advised.")
  sc <- scale_size_ordinal(...)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_binned
#' @export
scale_edge_size_binned <- function(name = waiver(), breaks = waiver(), labels = waiver(),
                                   limits = NULL, range = c(1, 6), n.breaks = NULL,
                                   nice.breaks = TRUE, trans = "identity", guide = "bins") {
  sc <- scale_size_binned(name = name, breaks = breaks, labels = labels, limits = limits,
                          range = range, n.breaks = n.breaks, nice.breaks = nice.breaks,
                          trans = trans, guide = guide)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_area
#'
#' @export
scale_edge_size_area <- function(..., max_size = 6) {
  sc <- scale_size_area(..., max_size = max_size)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#'
#' @inheritParams ggplot2::scale_size_binned_area
#'
#' @export
scale_edge_size_binned_area <- function(..., max_size = 6) {
  sc <- scale_size_binned_area(..., max_size = max_size)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_manual
#'
#' @export
scale_edge_size_manual <- function(..., values, breaks = waiver(), na.value = NA) {
  sc <- scale_size_manual(..., values = values, breaks = breaks, na.value = na.value)
  sc$aesthetics <- 'edge_size'
  sc
}
#' @rdname scale_edge_size
#'
#' @inheritParams ggplot2::scale_size_identity
#'
#' @export
scale_edge_size_identity <- function(..., guide = 'none') {
  sc <- scale_size_identity(..., guide = guide)
  sc$aesthetics <- 'edge_size'
  sc
}