-
Notifications
You must be signed in to change notification settings - Fork 114
/
scale_edge_width.R
83 lines (82 loc) · 2.81 KB
/
scale_edge_width.R
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
#' Edge width scales
#'
#' This set of scales defines width scales for edge geoms. Of all the new edge
#' scales defined in ggraph, this is the only one not having an equivalent in
#' ggplot2. In essence it mimics the use of size in
#' [ggplot2::geom_line()] and related. As almost all edge
#' representations are lines of some sort, edge_width will be used much more
#' often than edge_size. It is not necessary to spell out that it is an edge
#' scale as the geom knows if it is drawing an edge. Just write `width` and
#' not `edge_width` in the call to geoms.
#'
#' @return A ggproto object inheriting from `Scale`
#'
#' @family scale_edge_*
#'
#' @name scale_edge_width
#' @rdname scale_edge_width
#'
NULL
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_size_continuous
#'
#' @export
scale_edge_width_continuous <- 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$scale_name <- 'width_c'
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @export
scale_edge_width <- scale_edge_width_continuous
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_size_discrete
#' @export
scale_edge_width_discrete <- function(...) {
cli::cli_warn("Using {.field edge_width} for a discrete variable is not advised.")
sc <- scale_size_ordinal(...)
sc$scale_name <- 'width_d'
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_size_binned
#' @export
scale_edge_width_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$scale_name <- 'width_b'
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_size_manual
#'
#' @export
scale_edge_width_manual <- function(..., values, breaks = waiver(), na.value = NA) {
sc <- scale_size_manual(..., values = values, breaks = breaks, na.value = na.value)
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_size_identity
#'
#' @export
scale_edge_width_identity <- function(..., guide = 'none') {
sc <- scale_size_identity(..., guide = guide)
sc$aesthetics <- 'edge_width'
sc
}