Skip to content

Partial polar plots #5028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed

Partial polar plots #5028

wants to merge 16 commits into from

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented Nov 3, 2022

This is my take on #4462, that adds an end argument to coord_polar() to allow partial polar plots.

In brief:

  • There are no visual changes if end is not used.
  • It was straightforward to rescale to [start, end] instead of [0, 2π] to get the partial polar coordinates.
  • After that rescaling, I had to account for the bounding box of the circle sector.
  • The bit I found more difficult were the radius axis placement. I've resolved this as detailed below.

Normally, the axis is placed in the upper part of the y-axis. If we have only the lower part of a circle, I had to reflect the break positions:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

p <- ggplot(mpg, aes(displ, hwy, colour = factor(cyl))) +
  geom_point()

p + coord_polar(start = 0.5 * pi, end = 1.5 * pi)

If 0 or π are not in the [start, end] interval, I have placed the axis in the x-direction. (Below also reflected because left instead of right).

p + coord_polar(start = 1.25 * pi, end = 1.75 * pi)

If no integer multiple of 0.5π is in that interval, I can't appropriately place an axis anywhere. In that case, I've thrown a message with instructions.

p + coord_polar(start = 0.1 * pi, end = 0.4 * pi)
#> Could not find appropriate placement for the radius axis.
#> ℹ A radius axis requires the [`start`-`end`] range to include one of: `c(0,
#>   0.5, 1, 1.5) * pi`.

Created on 2022-11-03 by the reprex package (v2.0.1)

After the guides are ported over to the ggproto system, we might consider a more complete solution for axis placement than this.

@thomasp85
Copy link
Member

Is this still meaningful to get in or should we tackle it from anew after ggproto guides have been merged?

@teunbrand
Copy link
Collaborator Author

teunbrand commented Apr 15, 2023

I think the new ggproto guides don't interact with coord_polar() other than making coord_polar() skip doing proper guide stuff (as it wasn't using this), so these changes can safely co-exist. After the ggproto guides are merged, we can tackle bringing coord_polar() into the fold of guide-using coords, either in this PR or a new one. One might for example imagine an angle guide and radius guide for coord_polar().

@thomasp85 thomasp85 self-requested a review April 15, 2023 06:57
@thomasp85
Copy link
Member

ok, I'll do a review next week

@teunbrand
Copy link
Collaborator Author

Closing this PR in favour of #5334.

@teunbrand teunbrand closed this Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants