Skip to content

Awkward interaction between faceting, polar coordinates, and free scales #2815

@clauswilke

Description

@clauswilke

The concept of free scales under faceting doesn't quite work the way I would think it should when we're dealing with polar coordinates.

If we make set of facets with simple polar bar plots, we get partial pies because by default the scales are the same across facets:

library(ggplot2)

ggplot(mpg, aes(x = 1, fill = drv)) + 
  geom_bar() +
  coord_polar(theta = "y") +
  facet_wrap(~manufacturer)

Trying to make the scales free, so that each facet has its own theta scale, doesn't work, because coord_polar() needs a fixed aspect ratio and hence coord_polar()$is_free() returns FALSE:

ggplot(mpg, aes(x = 1, fill = drv)) + 
  geom_bar() +
  coord_polar(theta = "y") +
  facet_wrap(~manufacturer, scales = "free_y")
#> Error: coord_polar doesn't support free scales

However, we can make a version of coord_polar() that returns TRUE and it works just fine and makes the pie charts as expected. But then the aspect ratio is wrong:

cp <- coord_polar(theta = "y")
cp$is_free <- function() TRUE

ggplot(mpg, aes(x = 1, fill = drv)) + 
  geom_bar() +
  cp +
  facet_wrap(~manufacturer, scales = "free")

It seems to me that there are two separate concepts that are being muddled together, the aspect ratio of the facets and the limits of the scales. For most coordinate systems these two concepts are linked one-to-one, but for some (like coord_polar()) they are not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions