Skip to content

Commit b3bb675

Browse files
committed
add news bullet
1 parent b9edb48 commit b3bb675

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* New `layer(layout)` argument to interact with facets (@teunbrand, #3062)
34
* New parameters for `geom_label()` (@teunbrand and @steveharoz, #5365):
45
* The `linewidth` aesthetic is now applied and replaces the `label.size`
56
argument.

tests/testthat/test-facet-map.R

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,67 @@ test_that("wrap and grid can facet by a POSIXct variable", {
9393
expect_equal(loc_grid_row$PANEL, factor(1:3))
9494
})
9595

96+
test_that("wrap: layer layout is respected", {
97+
98+
df <- expand.grid(x = LETTERS[1:2], y = 1:3)
99+
100+
p <- ggplot(df, aes(x, y)) +
101+
geom_point(colour = "red", layout = "fixed") +
102+
geom_point() +
103+
geom_point(colour = "blue", layout = 5) +
104+
facet_wrap(~ x + y)
105+
b <- ggplot_build(p)
106+
107+
expect_equal(
108+
table(get_layer_data(b, i = 1L)$PANEL),
109+
table(rep(1:6, 6))
110+
)
111+
expect_equal(
112+
table(get_layer_data(b, i = 2L)$PANEL),
113+
table(1:6)
114+
)
115+
expect_equal(
116+
table(get_layer_data(b, i = 3L)$PANEL),
117+
table(factor(5, levels = 1:6))
118+
)
119+
})
120+
121+
test_that("grid: layer layout is respected", {
122+
123+
df <- expand.grid(x = LETTERS[1:2], y = 1:3)
124+
125+
p <- ggplot(df, aes(x, y)) +
126+
geom_point(colour = "red", layout = "fixed") +
127+
geom_point(colour = "green", layout = "fixed_rows") +
128+
geom_point(colour = "purple", layout = "fixed_cols") +
129+
geom_point() +
130+
geom_point(colour = "blue", layout = 5) +
131+
facet_grid(x ~ y)
132+
b <- ggplot_build(p)
133+
134+
expect_equal(
135+
table(get_layer_data(b, i = 1L)$PANEL),
136+
table(rep(1:6, 6))
137+
)
138+
expect_equal(
139+
table(get_layer_data(b, i = 2L)$PANEL),
140+
table(rep(1:6, 3))
141+
)
142+
expect_equal(
143+
table(get_layer_data(b, i = 3L)$PANEL),
144+
table(rep(1:6, 2))
145+
)
146+
expect_equal(
147+
table(get_layer_data(b, i = 4L)$PANEL),
148+
table(1:6)
149+
)
150+
expect_equal(
151+
table(get_layer_data(b, i = 5L)$PANEL),
152+
table(factor(5, levels = 1:6))
153+
)
154+
})
155+
156+
96157
# Missing behaviour ----------------------------------------------------------
97158

98159
a3 <- data_frame(

0 commit comments

Comments
 (0)