1
- # ' Arrange plots in a circular layout by aligning discrete axis
1
+ # ' Arrange plots in a circular layout
2
2
# '
3
3
# ' @description
4
4
# ' `r lifecycle::badge('experimental')`
5
5
# '
6
- # ' The `circle_discrete` function arranges plots by aligning discrete variables
7
- # ' in a circular layout.
6
+ # ' If `limits` is provided, a continuous variable will be required and aligned
7
+ # ' in the direction specified (`circle_continuous`). Otherwise, a discrete
8
+ # ' variable will be required and aligned (`circle_discrete`).
8
9
# '
9
- # ' @inheritParams stack_discrete
10
10
# ' @param radial A [`coord_radial()`][ggplot2::coord_radial] object that defines
11
11
# ' the global parameters for `coord_radial` across all plots in the layout.
12
12
# ' The parameters `start`, `end`, `direction`, and `expand` will be inherited
17
17
# ' indicating the direction in which the plot is added.
18
18
# ' - `outward`: The plot is added from the inner to the outer.
19
19
# ' - `inward`: The plot is added from the outer to the inner.
20
+ # ' @inheritParams stack_layout
21
+ # ' @return A `CircleLayout` object.
20
22
# ' @examples
21
23
# ' set.seed(123)
24
+ # '
22
25
# ' small_mat <- matrix(rnorm(56), nrow = 7)
23
26
# ' rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
24
27
# ' colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
25
28
# '
29
+ # ' # circle_layout
30
+ # ' # same for circle_discrete()
31
+ # ' circle_layout(small_mat) +
32
+ # ' ggalign() +
33
+ # ' geom_tile(aes(y = .column_index, fill = value)) +
34
+ # ' scale_fill_viridis_c() +
35
+ # ' align_dendro(aes(color = branch), k = 3L) +
36
+ # ' scale_color_brewer(palette = "Dark2")
37
+ # '
38
+ # ' # same for circle_continuous()
39
+ # ' circle_layout(mpg, limits = continuous_limits(c(3, 5))) +
40
+ # ' ggalign(mapping = aes(displ, hwy, colour = class)) +
41
+ # ' geom_point(size = 2) +
42
+ # ' ggalign(mapping = aes(displ, hwy, colour = class)) +
43
+ # ' geom_point(size = 2) &
44
+ # ' scale_color_brewer(palette = "Dark2") &
45
+ # ' theme_bw()
46
+ # '
47
+ # ' @export
48
+ circle_layout <- function (data = NULL , ... , radial = NULL ,
49
+ direction = " outward" , limits = waiver(),
50
+ theme = NULL ) {
51
+ if (is.waive(limits )) {
52
+ circle_discrete(
53
+ data = data , ... , radial = radial ,
54
+ direction = direction , theme = theme
55
+ )
56
+ } else {
57
+ circle_continuous(
58
+ data = data , ... , radial = radial ,
59
+ direction = direction , theme = theme , limits = limits
60
+ )
61
+ }
62
+ }
63
+
64
+ # ###########################################################
65
+ # ' @examples
66
+ # ' # circle_discrete()
26
67
# ' # direction outward
27
68
# ' circle_discrete(small_mat) +
28
69
# ' align_dendro(aes(color = branch), k = 3L) +
38
79
# ' scale_fill_viridis_c() +
39
80
# ' align_dendro(aes(color = branch), k = 3L) +
40
81
# ' scale_color_brewer(palette = "Dark2")
82
+ # '
41
83
# ' @export
84
+ # ' @rdname circle_layout
42
85
circle_discrete <- function (data = NULL , ... , radial = NULL ,
43
86
direction = " outward" , theme = NULL ) {
44
87
UseMethod(" circle_discrete" , data )
@@ -81,17 +124,8 @@ circle_discrete.function <- function(data = NULL, ...) {
81
124
circle_discrete.formula <- circle_discrete.function
82
125
83
126
# ###############################################################
84
- # ' Arrange plots in a circular layout by aligning continuous axis
85
- # '
86
- # ' @description
87
- # ' `r lifecycle::badge('experimental')`
88
- # '
89
- # ' The `circle_continuous` function arranges plots by aligning continuous
90
- # ' variables in a circular layout.
91
- # '
92
- # ' @inheritParams circle_discrete
93
- # ' @inheritParams stack_continuous
94
127
# ' @examples
128
+ # ' # circle_continuous()
95
129
# ' circle_continuous(mpg, limits = continuous_limits(c(3, 5))) +
96
130
# ' ggalign(mapping = aes(displ, hwy, colour = class)) +
97
131
# ' geom_point(size = 2) +
@@ -100,6 +134,7 @@ circle_discrete.formula <- circle_discrete.function
100
134
# ' scale_color_brewer(palette = "Dark2") &
101
135
# ' theme_bw()
102
136
# ' @export
137
+ # ' @rdname circle_layout
103
138
circle_continuous <- function (data = NULL , ... , radial = NULL ,
104
139
direction = " outward" , limits = NULL ,
105
140
theme = NULL ) {
@@ -161,50 +196,6 @@ new_circle_layout <- function(data, design, radial, direction, schemes = NULL,
161
196
)
162
197
}
163
198
164
- # ' Arrange plots in a circular layout
165
- # '
166
- # ' @description
167
- # ' `r lifecycle::badge('experimental')`
168
- # '
169
- # ' This function integrates the functionalities of `circle_discrete()` and
170
- # ' `circle_continuous()` into a single interface.
171
- # '
172
- # ' @inheritParams stack_layout
173
- # ' @return A `CircleLayout` object.
174
- # ' @seealso
175
- # ' - [`circle_discrete()`]
176
- # ' - [`circle_continuous()`]
177
- # ' @examples
178
- # ' set.seed(123)
179
- # '
180
- # ' # circle_discrete
181
- # ' small_mat <- matrix(rnorm(56), nrow = 7)
182
- # ' rownames(small_mat) <- paste0("row", seq_len(nrow(small_mat)))
183
- # ' colnames(small_mat) <- paste0("column", seq_len(ncol(small_mat)))
184
- # ' circle_layout(small_mat) +
185
- # ' ggalign() +
186
- # ' geom_tile(aes(y = .column_index, fill = value)) +
187
- # ' scale_fill_viridis_c() +
188
- # ' align_dendro(aes(color = branch), k = 3L) +
189
- # ' scale_color_brewer(palette = "Dark2")
190
- # '
191
- # ' # circle_continuous
192
- # ' circle_layout(mpg, limits = continuous_limits(c(3, 5))) +
193
- # ' ggalign(mapping = aes(displ, hwy, colour = class)) +
194
- # ' geom_point(size = 2) +
195
- # ' ggalign(mapping = aes(displ, hwy, colour = class)) +
196
- # ' geom_point(size = 2) &
197
- # ' scale_color_brewer(palette = "Dark2") &
198
- # ' theme_bw()
199
- # ' @export
200
- circle_layout <- function (data = NULL , ... , limits = waiver()) {
201
- if (is.waive(limits )) {
202
- circle_discrete(data = data , ... )
203
- } else {
204
- circle_continuous(data = data , limits = limits , ... )
205
- }
206
- }
207
-
208
199
# ###########################################################
209
200
# Used to place multiple objects in one axis
210
201
# ' @importFrom grid unit
0 commit comments