Skip to content

theta/r guides get theta/r theme elements - #5680

Merged
teunbrand merged 8 commits into
tidyverse:rc/3.5.0from
teunbrand:coord_radial_position_theme
Feb 13, 2024
Merged

teunbrand merged 8 commits into
tidyverse:rc/3.5.0from
teunbrand:coord_radial_position_theme

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This PR to the RC aims to fix an internally discussed issue.

Briefly, it makes the theme settings that axes in coord_radial() listen in on more consistent with coord_polar() in that the theta guide will use x.bottom when theta = "x" and y.left when theta = "y".

Unfortunately due to default margin settings, this looks pretty bad for the r-axis when theta = "y".

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

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  guides(theta.sec = "axis_theta", r.sec = "axis") +
  theme(
    axis.line.x.bottom = element_line(colour = 'red'),
    axis.line.x.top = element_line(colour = "blue"),
    axis.line.y.left = element_line(colour = "green"),
    axis.line.y.right = element_line(colour = "orange")
  )

p + coord_radial(theta = "x", donut = 0.5)

p + coord_radial(theta = "y", donut = 0.5)

Created on 2024-02-06 with reprex v2.1.0

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Feb 6, 2024
@teunbrand teunbrand changed the title coord_radial() axes get theta-aware theme styling theta/r guides get theta/r theme elements Feb 8, 2024
@teunbrand

Copy link
Copy Markdown
Collaborator Author

As suggested, the r/theta positions get their own theme elements.
I didn't implement theta.sec and r.sec theme elements, but you can control this at the guide level anyway.

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  coord_radial(theta = "x", donut = 0.5) +
  theme(
    axis.line.theta = element_line(colour = 'red'),
    axis.line.r = element_line(colour = "green")
  ) +
  guides(
    theta.sec = guide_axis_theta(theme = theme(axis.line.theta = element_line(colour = "blue"))),
    r.sec = guide_axis(theme = theme(axis.line.r = element_line(colour = "orange")))
  )

Created on 2024-02-08 with reprex v2.1.0

@teunbrand
teunbrand changed the base branch from main to rc/3.5.0 February 8, 2024 11:27

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Merge branch 'rc/3.5.0' into coord_radial_position_theme

# Conflicts:
#	tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg
#	tests/testthat/test-coord-polar.R
@teunbrand
teunbrand merged commit 389315e into tidyverse:rc/3.5.0 Feb 13, 2024
@teunbrand
teunbrand deleted the coord_radial_position_theme branch February 13, 2024 12:01
thomasp85 pushed a commit that referenced this pull request Feb 23, 2024
* swap theme suffix depending on `theta`

* pass theme properly in `guide_axis_theta()`

* add `theta` and `r` theme elements

* axis.text.r has symmetrical margins

* use new suffixes

* update tests

* update docs
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