R语言Marmap包

1.简介

In this vignette we introduce marmap, a package designed for manipulating bathymetric data in R. marmap uses simple latitude-longitude-depth data in ascii format and takes advantage of the advanced plotting tools available in R to build
publication-quality bathymetric maps. Functions to query data (bathymetry, sampling information...) directly by clicking on marmap maps are available. Bathymetric水深 and topographic地形 data can also be used to constrain the calculation of realistic shortest path distances.

2.1 Getting data into R

library(marmap)

问题

载入程辑包:‘marmap’

The following object is masked from ‘package:grDevices’:

    as.raster

解决:Rstudio  直接 重新加载启动

#It queries the ETOPO1 dataset [1] hosted on the NOAA server, based on coordinates and a resolution given by the user
papoue <- getNOAA.bathy(lon1 = 140, lon2 = 155,lat1 = -13, lat2 = 0, resolution = 10)

summary(papoue)#check the  data

2.2 Plotting bathymetric data

plot(papoue)

#First, we can plot a heat map, using the built in color palette. We can also add a scale in kilometers.
plot(papoue, image = TRUE)
scaleBathy(papoue, deg = 2, x = "bottomleft", inset = 5)

#use a custom color palette

blues <- colorRampPalette(c("red","purple","blue","cadetblue1","white"))
plot(papoue, image = TRUE, bpal = blues(100))

#For maps using the image option of plot.bathy(), you might see that the PDF rendering of your map is slightly different from the way it looks in R: the small space between cells becomes visible. This is probably due to the way your system handles PDFs. A simple way around this phenomenon is to export the map in a raster (rather than vector) format. You can use the tiff(), jpeg(),
bmp() or png() functions available in R.
This map looks a little crowded ; let’s dim the isobaths (dark grey color and lighter line width), and strengthen the coastline (black color and thicker line width). The deepest isobaths will be hard to see on a dark blue background ; we can therefore choose to plot these in light grey to improve contrast. The option drawlabel controls whether isobath labels (e.g. “-3000”) are plotted or not.

plot(papoue, image = TRUE, bpal = blues(100),deep = c(-9000, -3000, 0),shallow = c(-3000, -10, 0),step = c(1000, 1000, 0),
lwd = c(0.8, 0.8, 1), lty = c(1, 1, 1),col = c("lightgrey", "darkgrey", "black"),drawlabel = c(FALSE, FALSE, FALSE))


# Creating a custom palette of blues
blues <- c("lightsteelblue4", "lightsteelblue3","lightsteelblue2", "lightsteelblue1")
# Plotting the bathymetry with different colors for land and sea
plot(papoue, image = TRUE, land = TRUE, lwd = 0.1,bpal = list(c(0, max(papoue), "grey"),
c(min(papoue),0,blues)))
# Making the coastline more visible
plot(papoue, deep = 0, shallow = 0, step = 0,lwd = 0.4, add = TRUE)



2.3 Preparing maps in the Pacific antimeridian region#子午线区域

#a point at -170 longitude must be plotted using-170 + 360 = 190, not 170 nor -170

aleu <- getNOAA.bathy(165, -145, 50, 65, resolution = 5,antimeridian = TRUE)
plot(aleu, image = TRUE, land = TRUE, axes = FALSE, lwd=0.1,
bpal = list(c(0, max(aleu), grey(.7), grey(.9), grey(.95)),c(min(aleu), 0, "darkblue", "lightblue")))
plot(aleu, n = 1, lwd = 0.5, add = TRUE)
antimeridian.box(aleu)

summary(aleu)

#合并两块数据

a <- getGEBCO.bathy("east.nc")
b <- getGEBCO.bathy("west.nc")
stitched <- collate.bathy(a,b)

2.4 Irregularly-spaced data不规则间隔的数据xyz data

data(irregular)
head(irregular)
lon lat depth
1 -89.69973 46.01189 -17.4
2 -89.70065 46.01169 -16.9
3 -89.69893 46.01494 -1.0
4 -89.70036 46.00996 -18.5
5 -89.70294 46.00738 -6.6
6 -89.69942 46.01292 -15.7
plot(irregular$lon, irregular$lat, pch = 19, cex = 0.3, asp = 1)

#Using several functions from the raster package, we provide an easy way to transform such irregularly-spaced xyz data into a regularly-spaced grid. First,we transform the original data into a raster object of user-defined dimensions:
reg <- griddify(irregular, nlon = 40, nlat = 60)
class(reg)
[1] "RasterLayer"

attr(,"package")
[1] "raster"

#Then, we transform this object into a bathy object for easy plotting:
bat <- as.bathy(reg)
class(bat)
[1] "bathy"

# Plot the new bathy object
plot(bat, image = TRUE, lwd = 0.1)








 

猜你喜欢

转载自blog.csdn.net/hj18621829203/article/details/81333414