tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.51k stars 2.03k forks source link

Specify position of r axis for coord_radial when r_axis_inside = T #5805

Closed acebulsk closed 3 months ago

acebulsk commented 7 months ago

When using coord_radial we can move the r axis (aka y axis) inside using r_axis_inside = T. However, when r_axis_inside = T the position defaults to 0 degrees when plotting a full circle and this is confusing the r axis extends into the first value of the theta axis.

I would like to be able to control the position/angle of the r axis when it is inside the plot. For example below I would like to have the r axis at 45 degrees so it is not to be confused with the theta axis.

library(ggplot2)

# Generate data for each combination of circle (360 deg) and radius (0 to 90)
data <- expand.grid(
  angle = seq(0, 359, by = 1),
  radius = seq(0, 90, by = 1),
  value = 0.5
)

# Create the circular plot
ggplot(data, aes(x = angle, y = radius)) +
  geom_tile(alpha = 0.2) +
  coord_radial(
    r_axis_inside = T,
    expand = F
  ) +
  scale_x_continuous(breaks = seq(0, 270, 90)) +
  labs(title = "Circular Plot",
       x = "Angle (degrees)",
       y = "Radius")

Created on 2024-03-25 with reprex v2.1.0

Here is roughly what I am after:

Screenshot from 2024-03-25 17-27-57

teunbrand commented 7 months ago

I can understand why this is useful, but by extension we could also ask why we don't allow e.g. coord_cartesian() to place axes inside the panel at specified positions.

BenVolpe94 commented 5 months ago

Also looking for this feature! Being able to place the r-axis inside gives a much better view on the scale, but sometimes it overlaps with your data (see example below). If I was able to customize the angle it would be much easier to prevent overlapping image