Skip to content

Implement default crs for non-sf objects in coord_sf(). #3659

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

Merged
merged 31 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
38d4e10
Implement default crs for non-sf objects in coord_sf().
clauswilke Dec 6, 2019
64794d1
make limits work
clauswilke Dec 6, 2019
0a885b8
cleanup code, write documentation
clauswilke Dec 7, 2019
829b081
more accurately specify CRS
clauswilke Dec 7, 2019
b482d7b
handle missing or infinite values in sf_transform_xy().
clauswilke Dec 7, 2019
fe31077
fix package build
clauswilke Dec 7, 2019
325a458
properly reset bbox at beginning of plot generation
clauswilke Dec 8, 2019
6110b02
cleanup
clauswilke Dec 8, 2019
c583ced
check that the coord is of type CoordSf before
clauswilke Dec 9, 2019
aece1e4
scale limit improvements
clauswilke Dec 15, 2019
63a52d7
Register bounding box even for stat_sf_coordinates. Gives better defa…
clauswilke Dec 15, 2019
94c495d
Merge branch 'master' into coord-sf
clauswilke Jan 12, 2020
7ea08ae
Merge branch 'master' into coord-sf
clauswilke Feb 1, 2020
6831ab2
finalize handling of limits, improve documentation
clauswilke Feb 1, 2020
b590d64
unit tests for new coord_sf() features
clauswilke Feb 2, 2020
edcae20
alternative limit methods
clauswilke Feb 3, 2020
0942ae4
ensure point data is always numeric
clauswilke Feb 3, 2020
c5dd56a
expand documentation
clauswilke Feb 6, 2020
1e485e9
merge in master
clauswilke Feb 6, 2020
371af57
delete space
clauswilke Feb 6, 2020
9843333
capitalize crs
clauswilke Feb 6, 2020
11fa427
check against incorrect mapping
clauswilke Feb 11, 2020
385e4b9
update docs
clauswilke Feb 11, 2020
45b6b38
more limits methods
clauswilke Feb 11, 2020
4743813
better limits methods
clauswilke Feb 11, 2020
da26d4d
simplify error message
clauswilke Feb 12, 2020
5d39f18
Merge branch 'master' into coord-sf
clauswilke Feb 12, 2020
e4cdcd6
Merge branch 'master' into coord-sf
clauswilke Mar 9, 2020
9e97812
Merge branch 'master' into coord-sf
clauswilke Jun 23, 2020
ee0fb99
fix error message if scale limits inversion problem
clauswilke Jun 24, 2020
942d74c
reword warnings and error messages.
clauswilke Jun 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ export(scale_y_sqrt)
export(scale_y_time)
export(sec_axis)
export(set_last_plot)
export(sf_transform_xy)
export(should_stop)
export(stage)
export(standardise_aes_names)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ This is a small release focusing on fixing regressions introduced in 3.3.1.

* `annotation_raster()` adds support for native rasters. For large rasters,
native rasters render significantly faster than arrays (@kent37, #3388)

* `coord_sf()` now has an argument `default_crs` that specifies the coordinate
reference system (CRS) for non-sf layers and scale/coord limits. This argument
defaults to the World Geodetic System 1984 (WGS84), which means x and y positions
are interpreted as longitude and latitude. This is a potentially breaking change
for users who use projected coordinates in non-sf layers or in limits. Setting
`default_crs = NULL` recovers the old behavior. Further, authors of extension
packages implementing `stat_sf()`-like functionality are encouraged to look at the
source code of `stat_sf()`'s `compute_group()` function to see how to provide
scale-limit hints to `coord_sf()` (@clauswilke, #3659).

* Facet strips now have dedicated position-dependent theme elements
(`strip.text.x.top`, `strip.text.x.bottom`, `strip.text.y.left`,
Expand Down
68 changes: 47 additions & 21 deletions R/annotation-map.r
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
#' @include geom-map.r
NULL

#' Annotation: a maps
#' Annotation: a map
#'
#' Display a fixed map on a plot.
#' Display a fixed map on a plot. This function predates the [`geom_sf()`]
#' framework and does not work with sf geometry columns as input. However,
#' it can be used in conjunction with `geom_sf()` layers and/or
#' [`coord_sf()`] (see examples).
#'
#' @param map data frame representing a map. Most map objects can be
#' converted into the right format by using [fortify()]
#' @param ... other arguments used to modify aesthetics
#' @param map Data frame representing a map. See [`geom_map()`] for
#' details.
#' @param ... Other arguments used to modify visual parameters, such as
#' `colour` or `fill`.
#' @export
#' @examples
#' if (require("maps")) {
#' usamap <- map_data("state")
#' \dontrun{
#' if (requireNamespace("maps", quietly = TRUE)) {
#' # location of cities in North Carolina
#' df <- data.frame(
#' name = c("Charlotte", "Raleigh", "Greensboro"),
#' lat = c(35.227, 35.772, 36.073),
#' long = c(-80.843, -78.639, -79.792)
#' )
#'
#' seal.sub <- subset(seals, long > -130 & lat < 45 & lat > 40)
#' ggplot(seal.sub, aes(x = long, y = lat)) +
#' annotation_map(usamap, fill = NA, colour = "grey50") +
#' geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat))
#' }
#' p <- ggplot(df, aes(x = long, y = lat)) +
#' annotation_map(
#' map_data("state"),
#' fill = "antiquewhite", colour = "darkgrey"
#' ) +
#' geom_point(color = "blue") +
#' geom_text(
#' aes(label = name),
#' hjust = 1.105, vjust = 1.05, color = "blue"
#' )
#'
#' if (require("maps")) {
#' seal2 <- transform(seal.sub,
#' latr = cut(lat, 2),
#' longr = cut(long, 2))
#' # use without coord_sf() is possible but not recommended
#' p + xlim(-84, -76) + ylim(34, 37.2)
#'
#' ggplot(seal2, aes(x = long, y = lat)) +
#' annotation_map(usamap, fill = NA, colour = "grey50") +
#' geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat)) +
#' facet_grid(latr ~ longr, scales = "free", space = "free")
#' }
#' if (requireNamespace("sf", quietly = TRUE)) {
#' # use with coord_sf() for appropriate projection
#' p +
#' coord_sf(
#' crs = st_crs(3347),
#' xlim = c(-84, -76),
#' ylim = c(34, 37.2)
#' )
#'
#' # you can mix annotation_map() and geom_sf()
#' nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
#' p +
#' geom_sf(
#' data = nc, inherit.aes = FALSE,
#' fill = NA, color = "black", size = 0.1
#' ) +
#' coord_sf(crs = st_crs(3347))
#' }}}
annotation_map <- function(map, ...) {
# Get map input into correct form
if (!is.data.frame(map)) {
Expand Down
Loading