We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
coord_polar()
1 parent 4946960 commit acf3641Copy full SHA for acf3641
NEWS.md
@@ -1,5 +1,7 @@
1
# ggplot2 (development version)
2
3
+* `coord_polar()` can have free scales in facets (@teunbrand, #2815).
4
+
5
* The new argument `axes` in `facet_grid()` and `facet_wrap()` controls the
6
display of axes at interior panel positions. Additionally, the `axis.labels`
7
argument can be used to only draw tick marks or fully labelled axes
R/coord-polar.R
@@ -80,6 +80,8 @@ CoordPolar <- ggproto("CoordPolar", Coord,
80
81
aspect = function(details) 1,
82
83
+ is_free = function() TRUE,
84
85
distance = function(self, x, y, details) {
86
arc <- self$start + c(0, 2 * pi)
87
dir <- self$direction
R/coord-radial.R
@@ -79,6 +79,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
79
diff(details$bbox$y) / diff(details$bbox$x)
},
arc <- details$arc %||% c(0, 2 * pi)
if (self$theta == "x") {
R/facet-grid-.R
@@ -369,9 +369,7 @@ FacetGrid <- ggproto("FacetGrid", Facet,
369
if (!is.null(aspect_ratio) && (params$space_free$x || params$space_free$y)) {
370
cli::cli_abort("Free scales cannot be mixed with a fixed aspect ratio.")
371
}
372
- if (is.null(aspect_ratio) && !params$free$x && !params$free$y) {
373
- aspect_ratio <- coord$aspect(ranges[[1]])
374
- }
+ aspect_ratio <- aspect_ratio %||% coord$aspect(ranges[[1]])
375
if (is.null(aspect_ratio)) {
376
aspect_ratio <- 1
377
respect <- FALSE
R/facet-wrap.R
@@ -293,12 +293,9 @@ FacetWrap <- ggproto("FacetWrap", Facet,
293
structure(labels_df, type = "cols"),
294
params$labeller, theme)
295
296
- # If user hasn't set aspect ratio, and we have fixed scales, then
297
- # ask the coordinate system if it wants to specify one
298
- aspect_ratio <- theme$aspect.ratio
299
300
301
+ # If user hasn't set aspect ratio, ask the coordinate system if
+ # it wants to specify one
+ aspect_ratio <- theme$aspect.ratio %||% coord$aspect(ranges[[1]])
302
303
304
tests/testthat/test-coord-polar.R
@@ -79,6 +79,25 @@ test_that("Inf is squished to range", {
expect_equal(d[[3]]$theta, mapped_discrete(0))
})
+test_that("coord_polar can have free scales in facets", {
+ p <- ggplot(data_frame0(x = c(1, 2)), aes(1, x)) +
+ geom_col() +
+ coord_polar(theta = "y")
88
+ sc <- layer_scales(p + facet_wrap(~ x), 1, 1)
89
+ expect_equal(sc$y$get_limits(), c(0, 2))
90
91
+ sc <- layer_scales(p + facet_wrap(~ x, scales = "free"), 1, 1)
92
+ expect_equal(sc$y$get_limits(), c(0, 1))
93
94
+ sc <- layer_scales(p + facet_grid(x ~ .), 1, 1)
95
96
97
+ sc <- layer_scales(p + facet_grid(x ~ ., scales = "free"), 1, 1)
98
99
+})
100
101
test_that("coord_radial warns about axes", {
102
103
p <- ggplot(mtcars, aes(disp, mpg)) +
0 commit comments