forked from tidyverse/ggplot2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coord_trans()
now generates a warning when a transformation results…
… in x or y values being non-finite (tidyverse#2147).
- Loading branch information
1 parent
331977e
commit 1564029
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
context("coord_trans") | ||
|
||
test_that("warnings are generated when cord_trans() results in new infinite values", { | ||
p <- ggplot(head(diamonds, 20)) + | ||
geom_bar(aes(x = cut)) + | ||
coord_trans(y = "log10") | ||
|
||
p2 <- ggplot(data.frame(a = c(1, 2, 0), b = c(10, 6, 4)), aes(a, b)) + | ||
geom_point() + | ||
coord_trans(x = "log") | ||
|
||
expect_warning(ggplot_gtable(ggplot_build(p)), "Transformation introduced infinite values in y-axis") | ||
expect_warning(ggplot_gtable(ggplot_build(p2)), "Transformation introduced infinite values in x-axis") | ||
}) | ||
|
||
test_that("no warnings are generated when original data has Inf values, but no new Inf values created from the transformation", { | ||
p <- ggplot(data.frame(x = c(-Inf, 2, 0), y = c(Inf, 6, 4)), aes(x, y)) + | ||
geom_point() + | ||
coord_trans(x = 'identity') | ||
|
||
expect_silent(benchplot(p)) | ||
}) |