Repository navigation
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] 1Created 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, andCoordPolardon't follow the convention of treatingInfas the edge of the range. This PR fixes it.CoordSfIt seems
CoordSf$transform()just forget to squish infinite values to range ascoord_cartesian()does.CoordMapIn
CoordMap,Infcan be converted toNAbymapproj:: mapproject(). So, just applyingsquish_infinite()is not enough; we need to restore theInffrom the original data.CoordPolarFor angle (
theta),Infand-Infare squashed into0, which is both the start and the end of the circle. For radius (r),Infis squashed to0.4, the hardcoded value inr_rescale(), and-Infis squashed to0.Results
Created on 2018-11-26 by the reprex package (v0.2.1)