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

layer does not work as expected for creating a geom_density_2d plot #5571

Open
davidhodge931 opened this issue Dec 7, 2023 · 5 comments · May be fixed by #6222
Open

layer does not work as expected for creating a geom_density_2d plot #5571

davidhodge931 opened this issue Dec 7, 2023 · 5 comments · May be fixed by #6222

Comments

@davidhodge931
Copy link

library(tidyverse)

ggplot(faithful, aes(x = eruptions, y = waiting)) +
  geom_density_2d()

ggplot() +
  layer(
    geom = ggplot2::GeomDensity2d,
    stat = ggplot2::StatDensity2d,
    data = faithful,
    mapping = aes(x = eruptions, y = waiting),
    position = ggplot2::PositionIdentity,
  )

Created on 2023-12-08 with reprex v2.0.2

@davidhodge931 davidhodge931 changed the title layer does not work as expected for geom_density_2d layer does not work as expected for creating a geom_density_2d plot Dec 8, 2023
@teunbrand
Copy link
Collaborator

It needs contour = TRUE for it to work as expected, e.g.:

ggplot() +
  layer(
    geom = ggplot2::GeomDensity2d,
    stat = ggplot2::StatDensity2d,
    data = faithful,
    mapping = aes(x = eruptions, y = waiting),
    position = ggplot2::PositionIdentity,
    params = list(contour = TRUE)
  )

@davidhodge931
Copy link
Author

davidhodge931 commented Dec 8, 2023

Could GeomDensity2d default to contour = TRUE to match geom_density_2d defaults?

Likewise, GeomDensity2dFilled

@teunbrand
Copy link
Collaborator

I think that should be possible. Do you happen to have any interest in preparing a PR for this?

@davidhodge931
Copy link
Author

I'm not sure how to do this, sorry @teunbrand. I'm not familiar with how ggproto works

@teunbrand
Copy link
Collaborator

No worries, that is totally fine! We'll get around to this at some point I think.

I'm not saying you should have a look at these, but if you happen to be curious, these are some starting materials to peruse:
https://ggplot2-book.org/internals.html#sec-ggproto
https://ggplot2.tidyverse.org/articles/extending-ggplot2.html
https://ggplot2-book.org/extensions.html

@teunbrand teunbrand linked a pull request Dec 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants