-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Squish infinite values in coord_sf(), coord_map(), and coord_polar() #2972
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
Squish infinite values in coord_sf(), coord_map(), and coord_polar() #2972
Conversation
This seems reasonable to me. Are there other coords that have the same issue? |
Thanks, here's a table of
library(ggplot2)
library(purrr)
e <- as.environment("package:ggplot2")
coords_names <- ls(e, pattern = "^Coord")
coords <- map(set_names(coords_names), get, envir = e)
transforms <- coords %>%
map("transform") %>%
map(rlang::expr_text) %>%
map(sprintf, fmt = '<div class="highlight highlight-source-r"><pre>%s</pre></div>')
knitr::kable(
tibble::enframe(transforms),
format = "html",
escape = FALSE
)
Created on 2018-11-01 by the reprex package (v0.2.1) |
Hmm, library(ggplot2)
p <- ggplot(data.frame(x = 0, y = 0)) +
geom_point(aes(x,y)) +
annotate("text", -Inf, Inf, label = "Top-left", hjust = 0, vjust = 1)
patchwork::wrap_plots(
p + coord_map(),
p + coord_quickmap()
) Created on 2018-11-01 by the reprex package (v0.2.1) The problem is that library(ggplot2)
mapproj::mapproject(data.frame(x = c(-Inf, 0, 1), y = c(0, 1, Inf)))
#> $x
#> [1] -Inf 0 1
#>
#> $y
#> [1] 0 1 Inf
p <- ggplot(data.frame(x = 0, y = 0)) +
geom_point(aes(x,y)) +
annotate("text", -Inf, Inf, label = "Top-left", hjust = 0, vjust = 1) +
coord_map()
b <- ggplot_build(p)
mapproj::mapproject(data.frame(x = c(-Inf, 0, 1), y = c(0, 1, Inf)))
#> $x
#> [1] NA 0 NA
#>
#> $y
#> [1] NA 0.01745418 NA
#>
#> $range
#> [1] 0.00000000 0.00000000 0.01745418 0.01745418
#>
#> $error
#> [1] 1 Created on 2018-11-01 by the reprex package (v0.2.1) |
Maybe |
This also needs to wait for #3003. |
Ah, sorry, I forgot to add a NEWS bullete... Will add one and merge. |
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/ |
Fixes #2971 (and r-spatial/sf#879)
It seems
CoordSf
,CoordMap
, andCoordPolar
don't follow the convention of treatingInf
as the edge of the range. This PR fixes it.CoordSf
It seems
CoordSf$transform()
just forget to squish infinite values to range ascoord_cartesian()
does.CoordMap
In
CoordMap
,Inf
can be converted toNA
bymapproj:: mapproject()
. So, just applyingsquish_infinite()
is not enough; we need to restore theInf
from the original data.CoordPolar
For angle (
theta
),Inf
and-Inf
are squashed into0
, which is both the start and the end of the circle. For radius (r
),Inf
is squashed to0.4
, the hardcoded value inr_rescale()
, and-Inf
is squashed to0
.Results
Created on 2018-11-26 by the reprex package (v0.2.1)