# NOT RUN {
# The easiest way to produce a map is to use the limits
# argument and decimal degrees:
if(requireNamespace("ggOceanMapsData")) {
basemap(limits = 60)
}
# Bathymetry and glaciers can be added using the respective arguments:
# }
# NOT RUN {
basemap(limits = -60, bathymetry = TRUE, glaciers = TRUE)
# }
# NOT RUN {
# 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))
# }
# NOT RUN {
basemap(data = dt, bathymetry = TRUE) +
geom_spatial_point(data = dt, aes(x = lon, y = lat), color = "red")
# }
# NOT RUN {
# 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")
#> Error: `mapping` must be created by `aes()`
# }
# NOT RUN {
# 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)
if(requireNamespace("ggOceanMapsData")) {
basemap(data = dt) + geom_point(data = dt, aes(x = lon.proj, y = lat.proj))
}
# }
# NOT RUN {
# 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:
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")
# The limits are further expanded when using the data argument:
basemap(data = dt) +
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")
## To find UTM coordinates to limit a polar map:
basemap(limits = 60, projection.grid = TRUE)
basemap(limits = c(2.5e4, -2.5e6, 2e6, -2.5e5), shapefiles = "Arctic")
# Using custom shapefiles
data(bs_shapes, package = "ggOceanMapsData")
basemap(shapefiles = list(land = bs_land, glacier = NULL, bathy = bs_bathy),
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