Skip to content

Only use data_frame in tests - #3003

Merged
thomasp85 merged 31 commits into
tidyverse:masterfrom
thomasp85:new_data_frame
Nov 19, 2018
Merged

thomasp85 merged 31 commits into
tidyverse:masterfrom
thomasp85:new_data_frame

Conversation

@thomasp85

Copy link
Copy Markdown
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 requested a review from hadley November 15, 2018 20:57
@thomasp85 thomasp85 mentioned this pull request Nov 15, 2018
@clauswilke

Copy link
Copy Markdown
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
Copy Markdown
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

yutannihilation commented Nov 16, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Member Author

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

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

lock Bot commented May 18, 2019

Copy link
Copy Markdown

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