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

x/ylim Arguments in coord_fixed Don’t Seem to Be Applied to Contours: #5883

Closed
JStorey42 opened this issue May 4, 2024 · 1 comment
Closed

Comments

@JStorey42
Copy link

I'm unsure if this is actually a feature (perhaps I'm misinterpreting or missing something in the docs) but I've observed that using the x/ylim arguments in coord_fixed (and presumably analogous functions) seem to produce different results than declaring your limits using lims(). Specifically, contours that were originally cut off due to axis limits are no longer cut off using coord_fixed() and lims() with appropriate axis limits. However, passing (the same) appropriate axis limits to the x/ylim arguments within coord_fixed() results in the correct aspect ratio and limits, however, the contours are still cut off in the same place.

Am I missing something or is this a bug?

Thanks.

A simple contour plot that requires rescaling to accommodate all contours:

ggplot(mtcars) +
  stat_density2d(aes(x = mpg, y = wt)) 

image

Correcting axis limits to accommodate all contours with lims() and applying coord_fixed() works:

ggplot(mtcars) +
  stat_density2d(aes(x = mpg, y = wt)) +
  lims(x = c(5, 45), y = c(-5, 15)) +
  coord_fixed()

image

But when correcting axis limits with x/ylim within coord_fixed(), the contours remain cutoff:

ggplot(mtcars) +
  stat_density2d(aes(x = mpg, y = wt)) +
  coord_fixed(xlim = c(5, 45), ylim = c(-5, 15))

image

@thomasp85
Copy link
Member

This is expected behaviour though I can see why it may be surprising. The contour stat uses the scale limits (which are set with lims()) to figure out the extend of the contouring. The xlim and ylim arguments in the coords are setting the coordinate limits and act more like a zoom level for the final graphical representation

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

No branches or pull requests

2 participants