# The easiest way to produce a map is to use the limits
# argument and decimal degrees:
basemap(limits = 60) # synonym to basemap(60)
# \donttest{
# Bathymetry can be added using the respective argument:
basemap(limits = -60, bathymetry = TRUE)
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) +
ggspatial::geom_spatial_point(data = dt, aes(x = lon, y = lat),
color = "red")
}
if (FALSE) {
# Note that writing out data = dt is required because there are multiple
# underlying ggplot layers plotted already:
basemap(data = dt) +
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), 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 limits are further expanded when using the data argument:
dt <- data.frame(lon = c(-160, 160, 160, -160), lat = c(80, 80, 60, 60))
if(requireNamespace("ggspatial", quietly = TRUE)) {
basemap(data = dt) +
ggspatial::geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
fill = NA, color = "red")
# Rotate:
basemap(data = dt, rotate = TRUE) +
ggspatial::geom_spatial_polygon(data = dt, aes(x = lon, y = lat),
fill = NA, color = "red")
}
# 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 (requires download):
data(bs_shapes, package = "ggOceanMapsData")
basemap(shapefiles = list(land = bs_land))#'
# 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)
# Rename axis labels
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), rotate = TRUE) +
theme(axis.title = element_blank(),
axis.text = element_blank(),
axis.ticks.x = element_blank(),
axis.ticks.y = element_blank()
)
# }
Run the code above in your browser using DataLab