-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathscale_edge_width.R
More file actions
119 lines (118 loc) · 2.61 KB
/
Copy pathscale_edge_width.R
File metadata and controls
119 lines (118 loc) · 2.61 KB
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
117
118
119
#' Edge width scales
#'
#' This set of scales defines width scales for edge geoms. In essence it mimics
#' the use of `linewidth` 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_linewidth_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_linewidth_continuous(
name = name,
breaks = breaks,
labels = labels,
limits = limits,
range = range,
trans = trans,
guide = guide
)
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @export
scale_edge_width <- scale_edge_width_continuous
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_linewidth_discrete
#' @export
scale_edge_width_discrete <- function(...) {
cli::cli_warn(
"Using {.field edge_width} for a discrete variable is not advised."
)
sc <- scale_linewidth_ordinal(...)
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_linewidth_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_linewidth_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_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_linewidth_manual
#'
#' @export
scale_edge_width_manual <- function(
...,
values,
breaks = waiver(),
na.value = NA
) {
sc <- scale_linewidth_manual(
...,
values = values,
breaks = breaks,
na.value = na.value
)
sc$aesthetics <- 'edge_width'
sc
}
#' @rdname scale_edge_width
#'
#' @inheritParams ggplot2::scale_linewidth_identity
#'
#' @export
scale_edge_width_identity <- function(..., guide = 'none') {
sc <- scale_linewidth_identity(..., guide = guide)
sc$aesthetics <- 'edge_width'
sc
}