Skip to content
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

Custom inside-axis position for coord_radial() #5908

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

@teunbrand teunbrand commented May 24, 2024

This PR aims to fix #5805.

Briefly, you can now use numeric values for coord_radial(r.axis.inside) that will place the radius axis at some specified position of the theta axis.

I think it is probably best illustrated how it works.
Let's make plot with clock-positions.

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

set.seed(42)
df <- data.frame(x = runif(100, max = 12), y = rnorm(100))

p <- ggplot(df, aes(x, y)) +
  geom_point() +
  scale_x_continuous(limits = c(0, 12), breaks = 1:12, expand = c(0, 0)) +
  theme(axis.line = element_line())

This is how one would set the position:

p + coord_radial(r.axis.inside = 4.5)

If for some reason you have secondary axes, you can set a vector to control primary and secondary separately.

p + coord_radial(r.axis.inside = c(4.5, 7)) +
  guides(r.sec = "axis")

Out of bounds axes get squished to the nearest limit.

p + coord_radial(r.axis.inside = -10)

Created on 2024-05-24 with reprex v2.1.0

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.

Specify position of r axis for coord_radial when r_axis_inside = T
1 participant