英文:
How to fix poor bathymetry resolution using "ggOceanMaps" package in R?
问题
我正在使用R中的ggOceanMaps,并尝试创建一个显示南加利福尼亚的海底地形数据的地图。然而,海底地形数据显示模糊,这让我认为这个包可能没有足够好的海底地形数据来制作一个特定区域的放大地图。有没有人知道这个问题是否可以解决,或者我应该使用另一个包?
这是我使用的代码:
dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE)
我得到了一个漂亮的地图,但海底地形分辨率不好。
英文:
I am using ggOceanMaps in R and I tried to create a map of Southern California with bathymetry data. However, the bathymetry is blurred out, which makes me think the package does not have good bathymetry data to make a close-up map of a given area. Does anyone know if the problem can be fixed or if I should use another package?
This is the code I used:
dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE)
I got a nice map but with bad bathymetric resolution.
答案1
得分: 1
使用 ggOceanMaps 的新版本(2.0;希望很快可以在CRAN上找到),您可以绘制高达15秒弧分辨率的栅格海底地形:
library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpjBq0J0. This
#> means that any downloaded map data need to be downloaded again when you
#> restart R. To avoid this problem, change the default path to a
#> permanent folder on your computer. Add following lines to your
#> .Rprofile file: {.ggOceanMapsenv <- new.env(); .ggOceanMapsenv$datapath
#> <- 'YourCustomPath'}. You can use usethis::edit_r_profile() to edit the
#> file.'~/Documents/ggOceanMapsLargeData'would make it in a writable
#> folder on most operating systems.
options(ggOceanMaps.datapath = "~/Documents/ggOceanMapsLargeData")
packageVersion("ggOceanMaps")
#> [1] '2.0.0'
dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE, bathy.style = "rcb")
<!-- -->
您可以使用任何栅格数据,例如marmap来下载ETOPO栅格数据,分辨率高达15秒弧分辨率(查看marmap::getNOAA.bathy()
中的resolution
参数):
library(marmap); library(stars); library(sf)
#> Registered S3 methods overwritten by 'adehabitatMA':
#> method from
#> print.SpatialPixelsDataFrame sp
#> print.SpatialPixels sp
#>
#> Attaching package: 'marmap'
#> The following object is masked from 'package:grDevices':
#>
#> as.raster
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
limits <- auto_limits(dt, expand.factor = 1.1)$projLimits
bm <- basemap(data = dt)
mar_bathy <- marmap::getNOAA.bathy(lon1 = limits["xmin"], lon2 = limits["xmax"], lat1 = limits["ymin"], lat2 = limits["ymax"])
#> Querying NOAA database ...
#> This may take seconds to minutes, depending on grid size
#> Building bathy matrix ...
bathy <- raster_bathymetry(stars::st_as_stars(marmap::as.raster(mar_bathy)), depths = NULL)
#> | | | 0% | |========= | 12% | |================== | 25% | |========================== | 38% | |=================================== | 50% | |============================================ | 62% | |==================================================== | 75% | |============================================================= | 88% | |======================================================================| 100%
p <- bm +
stars::geom_stars(data = bathy$raster) +
ggplot2::scale_fill_gradientn(
name = "Depth (m)", breaks = seq(0,5e3,1e3), limits = c(0,NA),
colors = colorRampPalette(c("#F7FBFF", "#DEEBF7", "#9ECAE1", "#4292C6", "#08306B"))(8)
)
reorder_layers(p)
<!-- -->
至于其他选择,您还可以使用marmap包绘制海底地形图:
marmap::autoplot.bathy(mar_bathy, geom=c("r", "c"), colour="white", size=0.1) + marmap::scale_fill_etopo()
#> Warning in ggplot2::geom_raster(ggplot2::aes_string(fill = "z"), ...): Ignoring
#> unknown parameters: `colour` and `size`
<!-- -->
<sup>创建于2023年6月30日,使用reprex v2.0.2</sup>
英文:
With the new version of ggOceanMaps (2.0; hopefully soon on CRAN), you can plot raster bathymetries up to 15 arc-second resolution:
library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpjBq0J0. This
#> means that any downloaded map data need to be downloaded again when you
#> restart R. To avoid this problem, change the default path to a
#> permanent folder on your computer. Add following lines to your
#> .Rprofile file: {.ggOceanMapsenv <- new.env(); .ggOceanMapsenv$datapath
#> <- 'YourCustomPath'}. You can use usethis::edit_r_profile() to edit the
#> file.'~/Documents/ggOceanMapsLargeData'would make it in a writable
#> folder on most operating systems.
options(ggOceanMaps.datapath = "~/Documents/ggOceanMapsLargeData")
packageVersion("ggOceanMaps")
#> [1] '2.0.0'
dt <- data.frame(lon = c(-125, -125, -111, -111), lat = c(28, 37, 37, 28))
basemap(data = dt, bathymetry = TRUE, bathy.style = "rcb")
<!-- -->
You can use any raster data, for example, marmap to download ETOPO raster data up to 15 arc-second resolution (see the resolution
argument in marmap::getNOAA.bathy()
)
library(marmap); library(stars); library(sf)
#> Registered S3 methods overwritten by 'adehabitatMA':
#> method from
#> print.SpatialPixelsDataFrame sp
#> print.SpatialPixels sp
#>
#> Attaching package: 'marmap'
#> The following object is masked from 'package:grDevices':
#>
#> as.raster
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
limits <- auto_limits(dt, expand.factor = 1.1)$projLimits
bm <- basemap(data = dt)
mar_bathy <- marmap::getNOAA.bathy(lon1 = limits["xmin"], lon2 = limits["xmax"], lat1 = limits["ymin"], lat2 = limits["ymax"])
#> Querying NOAA database ...
#> This may take seconds to minutes, depending on grid size
#> Building bathy matrix ...
bathy <- raster_bathymetry(stars::st_as_stars(marmap::as.raster(mar_bathy)), depths = NULL)
#> | | | 0% | |========= | 12% | |================== | 25% | |========================== | 38% | |=================================== | 50% | |============================================ | 62% | |==================================================== | 75% | |============================================================= | 88% | |======================================================================| 100%
p <- bm +
stars::geom_stars(data = bathy$raster) +
ggplot2::scale_fill_gradientn(
name = "Depth (m)", breaks = seq(0,5e3,1e3), limits = c(0,NA),
colors = colorRampPalette(c("#F7FBFF", "#DEEBF7", "#9ECAE1", "#4292C6", "#08306B"))(8)
)
reorder_layers(p)
<!-- -->
As for alternatives, you can also use the marmap package to plot bathymetric maps:
marmap::autoplot.bathy(mar_bathy, geom=c("r", "c"), colour="white", size=0.1) + marmap::scale_fill_etopo()
#> Warning in ggplot2::geom_raster(ggplot2::aes_string(fill = "z"), ...): Ignoring
#> unknown parameters: `colour` and `size`
<!-- -->
<sup>Created on 2023-06-30 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论