Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `coord_polar()` can have free scales in facets (@teunbrand, #2815).

* New `display` argument in `guide_colourbar()` supplants the `raster` argument.
In R 4.1.0 and above, `display = "gradient"` will draw a gradient.
* When using `geom_dotplot(binaxis = "x")` with a discrete y-variable, dots are
Expand Down
2 changes: 2 additions & 0 deletions R/coord-polar.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ CoordPolar <- ggproto("CoordPolar", Coord,

aspect = function(details) 1,

is_free = function() TRUE,

distance = function(self, x, y, details) {
arc <- self$start + c(0, 2 * pi)
dir <- self$direction
Expand Down
2 changes: 2 additions & 0 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
diff(details$bbox$y) / diff(details$bbox$x)
},

is_free = function() TRUE,

distance = function(self, x, y, details) {
arc <- details$arc %||% c(0, 2 * pi)
if (self$theta == "x") {
Expand Down
4 changes: 1 addition & 3 deletions R/facet-grid-.R
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ FacetGrid <- ggproto("FacetGrid", Facet,
if (!is.null(aspect_ratio) && (params$space_free$x || params$space_free$y)) {
cli::cli_abort("Free scales cannot be mixed with a fixed aspect ratio.")
}
if (is.null(aspect_ratio) && !params$free$x && !params$free$y) {
aspect_ratio <- coord$aspect(ranges[[1]])
}
aspect_ratio <- aspect_ratio %||% coord$aspect(ranges[[1]])
if (is.null(aspect_ratio)) {
aspect_ratio <- 1
respect <- FALSE
Expand Down
9 changes: 3 additions & 6 deletions R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,9 @@ FacetWrap <- ggproto("FacetWrap", Facet,
structure(labels_df, type = "cols"),
params$labeller, theme)

# If user hasn't set aspect ratio, and we have fixed scales, then
# ask the coordinate system if it wants to specify one
aspect_ratio <- theme$aspect.ratio
if (is.null(aspect_ratio) && !params$free$x && !params$free$y) {
aspect_ratio <- coord$aspect(ranges[[1]])
}
# 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]])

if (is.null(aspect_ratio)) {
aspect_ratio <- 1
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-coord-polar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

sc <- layer_scales(p + facet_wrap(~ x), 1, 1)
expect_equal(sc$y$get_limits(), c(0, 2))

sc <- layer_scales(p + facet_wrap(~ x, scales = "free"), 1, 1)
expect_equal(sc$y$get_limits(), c(0, 1))

sc <- layer_scales(p + facet_grid(x ~ .), 1, 1)
expect_equal(sc$y$get_limits(), c(0, 2))

sc <- layer_scales(p + facet_grid(x ~ ., scales = "free"), 1, 1)
expect_equal(sc$y$get_limits(), c(0, 1))
})

test_that("coord_radial warns about axes", {

p <- ggplot(mtcars, aes(disp, mpg)) +
Expand Down