Skip to content

fix stat_contour() for irregular data grids. #3907

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

Merged
merged 3 commits into from
Mar 22, 2020

Conversation

clauswilke
Copy link
Member

Closes #3906.

library(ggplot2)

v <- ggplot(faithfuld, aes(waiting, eruptions, z = density)) +
  geom_point(aes(color = density)) + geom_contour(color = "white")

v

v + scale_x_log10()

Created on 2020-03-21 by the reprex package (v0.3.0)

@clauswilke clauswilke requested a review from paleolimbot March 22, 2020 00:07
Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

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

Just a few comments for your consideration!


raster <- matrix(NA_real_, nrow = nrow, ncol = ncol)
raster[cbind(nrow - y_pos, x_pos + 1)] <- data$z
raster[cbind(y_pos, x_pos)] <- data$z

Copy link
Member

Choose a reason for hiding this comment

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

This looks great! I wrote this based on the code in GeomRaster because it was faster...before it was:

raster <- tapply(data$z, data[c("x", "y")], identity)

(I found that here in case you want to look at the context)

It might be worth checking whether that is faster (I suspect your way is better)

Copy link
Member Author

Choose a reason for hiding this comment

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

tapply() is ~40% slower.

As an aside, we're doing a lot of work wrangling the data into the right format for isoband and then back out. It'd probably be more efficient to just write an isoband function that takes the data in the format preferred by ggplot2 and returns it in a format that can be used directly. But that's for another day.

@clauswilke clauswilke merged commit 53815f8 into tidyverse:master Mar 22, 2020
@clauswilke clauswilke deleted the issue-3906-geom-contour branch March 22, 2020 17:19
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.

geom_contour incompatible with scale_x_log10 and scale_y_log10
2 participants