This is essentially a follow up question on How does ggplot calculate its default breaks? and I came across this when trying to find a slightly more elegant solution for How to add y-axis labels inside coord_polar graph ggplot?.
Apparently, the breaks are always calculated with scales::extended_breaks. However, it seems that the limits of those breaks are dropped with polar coordinates, as well as with a legend guide on continuous data.
Where does this happen?
library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = mpg, size = hp)) +
geom_point() +
coord_polar() +
labs(color = 'am')
Compare
with
scales::extended_breaks()(mtcars$mpg)
#> [1] 10 15 20 25 30 35
scales::extended_breaks()(mtcars$hp)
#> [1] 50 100 150 200 250 300 350
Created on 2023-04-01 with reprex v2.0.2
As I mentioned in my comment the issue with both the guides for non-positional scales and
coord_polaris that the scale or more exactly the limits don't get expanded. Forcoord_polareven the default exapnsion is set to zero which happens inCoordPolar$setup_panel_params:As a consequence the lower and upper breaks returned by
scales::breaks_extendedwill in general get dropped as it does not fall inside the limits.This said, one option would be to extend the
limitsor to use a custom function which does this by computing thelimitsasrange(scales::breaks_extended()):