# The easiest way to produce a map is to use the limits
# argument and decimal degrees:
-# \donttest{
-# if(requireNamespace("ggOceanMapsData", quietly = TRUE)) {
-basemap(limits = 60)
+basemap(limits = 60) # synonym to basemap(60)
-
-# Bathymetry and glaciers can be added using the respective arguments:
-
-basemap(limits = -60, bathymetry = TRUE, glaciers = TRUE)
+# \donttest{
+# Bathymetry can be added using the respective argument:
+basemap(limits = -60, bathymetry = TRUE)
-# The easiest way to add data on the maps is to use the ggspatial functions:
+if (FALSE) {
+# Glaciers require a download in the new version:
+basemap(limits = -60, glaciers = TRUE, shapefiles = "Arctic")
+}
+# The easiest way to add data on the maps is to use the ggspatial functions:
dt <- data.frame(lon = c(-150, 150), lat = c(60, 90))
-
+if(requireNamespace("ggspatial", quietly = TRUE)) {
basemap(data = dt, bathymetry = TRUE) +
-geom_spatial_point(data = dt, aes(x = lon, y = lat), color = "red")
+ ggspatial::geom_spatial_point(data = dt, aes(x = lon, y = lat),
+ color = "red")
+}
#> Assuming `crs = 4326` in stat_spatial_identity()
-
if (FALSE) {
# Note that writing out data = dt is required because there are multiple
# underlying ggplot layers plotted already:
basemap(data = dt) +
-geom_spatial_point(dt, aes(x = lon, y = lat), color = "red")
+ggspatial::geom_spatial_point(dt, aes(x = lon, y = lat), color = "red")
#> Error: `mapping` must be created by `aes()`
}
# If you want to use native ggplot commands, you need to transform your data
# to the projection used by the map:
-
dt <- transform_coord(dt, bind = TRUE)
-basemap(data = dt) + geom_point(data = dt, aes(x = lon.proj, y = lat.proj))
+basemap(data = dt) +
+ geom_point(data = dt, aes(x = lon.proj, y = lat.proj), color = "red")
# The limits argument of length 4 plots a map anywhere in the world:
-
basemap(limits = c(100, 160, -20, 30), bathymetry = TRUE)
-# The argument leads to expanded maps towards poles:
+# The limits are further expanded when using the data argument:
dt <- data.frame(lon = c(-160, 160, 160, -160), lat = c(80, 80, 60, 60))
-basemap(limits = c(160, -160, 60, 80)) +
-geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
-fill = NA, color = "red")
-#> `geom_polypath()` is deprecated: use `ggplot2::geom_polygon()` with the `subgroup` aesthetic
-#> Assuming `crs = 4326` in stat_spatial_identity()
-
-
-# The limits are further expanded when using the data argument:
-
+if(requireNamespace("ggspatial", quietly = TRUE)) {
basemap(data = dt) +
-geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
-fill = NA, color = "red")
-#> `geom_polypath()` is deprecated: use `ggplot2::geom_polygon()` with the `subgroup` aesthetic
-#> Assuming `crs = 4326` in stat_spatial_identity()
-
+ ggspatial::geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
+ fill = NA, color = "red")
# Rotate:
-
basemap(data = dt, rotate = TRUE) +
-geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
- fill = NA, color = "red")
+ ggspatial::geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
+ fill = NA, color = "red")
+}
+#> `geom_polypath()` is deprecated: use `ggplot2::geom_polygon()` with the `subgroup` aesthetic
#> `geom_polypath()` is deprecated: use `ggplot2::geom_polygon()` with the `subgroup` aesthetic
#> Assuming `crs = 4326` in stat_spatial_identity()
-
+
+
+# Alternative:
+basemap(data = dt, rotate = TRUE) +
+ geom_polygon(data = transform_coord(dt, rotate = TRUE),
+ aes(x = lon, y = lat), fill = NA, color = "red")
+
## To find UTM coordinates to limit a polar map:
basemap(limits = 60, projection.grid = TRUE)
-
+
+
+if (FALSE) {
+# (Arctic shapes require a download in 2.0)
basemap(limits = c(2.5e4, -2.5e6, 2e6, -2.5e5), shapefiles = "Arctic")
-
-# Using custom shapefiles
+# Using custom shapefiles (requires download):
data(bs_shapes, package = "ggOceanMapsData")
-basemap(shapefiles = list(land = bs_land),
-bathymetry = TRUE)
-
+basemap(shapefiles = list(land = bs_land))#'
-# grid.col = NA removes grid lines, rotate = TRUE rotates northwards
+# Premade shapefiles from ggOceanMapsLargeData (requires download):
+basemap("BarentsSea", bathymetry = TRUE)
+}
+# grid.col = NA removes grid lines, rotate = TRUE rotates northwards:
basemap(limits = c(-180, -140, 50, 70), grid.col = NA, rotate = TRUE)
-
+#> Warning: only first part of geometrycollection is retained
+
# Rename axis labels
-basemap(limits = c(-140, -105, 20, 40), bathymetry = TRUE) + xlab("Lat")
-
+basemap(limits = c(-140, -105, 20, 40), bathymetry = TRUE) + xlab("Lat")
+
# Remove axis labels
-basemap(limits = c(0, 60, 68, 80)) + labs(x = NULL, y = NULL)
-
+basemap(limits = c(0, 60, 68, 80)) + labs(x = NULL, y = NULL)
+
basemap(limits = c(0, 60, 68, 80), rotate = TRUE) +
-theme(axis.title = element_blank(),
- axis.text = element_blank(),
- axis.ticks.x = element_blank(),
- axis.ticks.y = element_blank()
+theme(axis.title = element_blank(),
+ axis.text = element_blank(),
+ axis.ticks.x = element_blank(),
+ axis.ticks.y = element_blank()
)
-
-# }
+
# }