且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ggplot2和marmap绘制测深图和海岸线

更新时间:2023-02-14 12:51:39

以下是一种方法:

获取大量数据:

library(marmap)
Bathy <- getNOAA.bathy(lon1 = 37, lon2 = 38.7,
                       lat1 = -45.5, lat2 = -47.3, resolution = 1)

将其转换为矩阵:

Bathy <- as.matrix(Bathy)
class(Bathy) <- "matrix"

现在将其重塑为长格式并绘图

now reshape it to long format and plot

library(tidyverse)

Bathy %>%
  as.data.frame() %>%
  rownames_to_column(var = "lon") %>%
  gather(lat, value, -1) %>%
  mutate_all(funs(as.numeric)) %>%
  ggplot()+
  geom_contour(aes(x = lon, y = lat, z = value), bins = 10, colour = "black") +
  coord_map()