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

Only use data_frame in tests #3003

Merged
merged 31 commits into from
Nov 19, 2018
Merged

Conversation

thomasp85
Copy link
Member

Some tests were added between the new_data_frame implementation and it's merge that used the now masked data.frame constructor. This PR fixes these so tests now passes

#	R/plot-build.r
@thomasp85 thomasp85 mentioned this pull request Nov 15, 2018
@clauswilke
Copy link
Member

I see one more problem, here:

ggplot(faithful, aes(x = eruptions, y = waiting)) +
stat_density2d(aes(fill = stat(level)), geom = "polygon", colour = "white") +
xlim(0.5, 6) + ylim(40, 110)

Not immediately sure what the cause is.

library(ggplot2)
ggplot(faithful, aes(x = eruptions, y = waiting)) +
  stat_density2d(aes(fill = stat(level)), geom = "polygon", colour = "white") +
  xlim(0.5, 6) + ylim(40, 110)
#> Warning in validDetails.polygon(x): NAs introduced by coercion

Created on 2018-11-15 by the reprex package (v0.2.1)

@clauswilke
Copy link
Member

One other, minor issue that could be fixed as part of this PR: The rep() inside max() seems superfluous here:

nlevel = rep(levels, lengths) / max(rep(levels, lengths), na.rm = TRUE),

@yutannihilation
Copy link
Member

yutannihilation commented Nov 16, 2018

GeomPolygon's error seems because now munched$group is character here, whereas polygonGrob() only accepts numeric vectors. Previously, it was factor. I didn't know the mercy of stringsAsFactors secretly saved us...

ggplot2/R/geom-polygon.r

Lines 96 to 105 in 4380cb9

polygonGrob(munched$x, munched$y, default.units = "native",
id = munched$group,
gp = gpar(
col = first_rows$colour,
fill = alpha(first_rows$fill, first_rows$alpha),
lwd = first_rows$size * .pt,
lty = first_rows$linetype
)
)
)

@yutannihilation
Copy link
Member

The group comes from here. So you can wrap this as.factor() or convert it to integer before passing it to polygonGrob(). I feel the latter approach is right, but I'm not fully sure what it is supposed to be.

ggplot2/R/stat-contour.r

Lines 92 to 101 in 4380cb9

groups <- paste(data$group[1], sprintf("%03d", pieces), sep = "-")
new_data_frame(list(
level = rep(levels, lengths),
nlevel = rep(levels, lengths) / max(rep(levels, lengths), na.rm = TRUE),
x = xs,
y = ys,
piece = pieces,
group = groups
), n = length(xs))

@thomasp85
Copy link
Member Author

Thanks - weirdly this didn't pop up locally... 🤔

@thomasp85 thomasp85 merged commit 2e9ceb7 into tidyverse:master Nov 19, 2018
@lock
Copy link

lock bot commented May 18, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants