Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ggplot2和marmap绘制水深测量和海岸线_R_Ggplot2_Maps - Fatal编程技术网

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

使用ggplot2和marmap绘制水深测量和海岸线,r,ggplot2,maps,R,Ggplot2,Maps,我环顾四周,没有找到一个很好的解决方案。 我想用ggplot2在经纬度图上绘制一些数据,用marmap在海岸线加测深图上绘制,所有数据都在一个单独的图上 此脚本用于打印mydata ggplot(data = ctd, aes(x = Longitude, y = Latitude)) + geom_raster(aes(fill = Temp)) + scale_fill_gradientn(colours = rev(my_colours)) + geom_contour(aes

我环顾四周,没有找到一个很好的解决方案。 我想用
ggplot2
在经纬度图上绘制一些数据,用
marmap
在海岸线加测深图上绘制,所有数据都在一个单独的图上

此脚本用于打印mydata

ggplot(data = ctd, aes(x = Longitude, y = Latitude)) +
  geom_raster(aes(fill = Temp)) +
  scale_fill_gradientn(colours = rev(my_colours)) +
  geom_contour(aes(z = Temp), binwidth = 2, colour = "black", alpha = 0.2) +

  #plot stations locations
  geom_point(data = ctd, aes(x = Longitude, y = Latitude),
             colour = 'black', size = 3, alpha = 1, shape = 15) +

  #plot legends
      labs(y = "Latitude", x = "Longitude", fill = "Temp (°C)") +
      coord_cartesian(expand = 0)+
      ggtitle("Temperature distribution") 
使用
marmap
I下载水深测量

library(marmap)
Bathy <- getNOAA.bathy(lon1 = 37, lon2 = 38.7,
                       lat1 = -45.5, lat2 = -47.3, resolution = 1)
库(marmap)
Bathy以下是一种方法:

获取洗澡数据:

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

好吧,有一个marmap函数。它被称为
autoplot.bathy()
。你查过它的帮助文件了吗

library(marmap) ; library(ggplot2)

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

ctd <- data.frame(Longitude = c(37.5, 38, 38.5), Latitude = c(-47, -46.5, -46))

autoplot.bathy(Bathy, geom=c("tile","contour")) +
    scale_fill_gradient2(low="dodgerblue4", mid="gainsboro", high="darkgreen") +
    geom_point(data = ctd, aes(x = Longitude, y = Latitude),
               colour = 'black', size = 3, alpha = 1, shape = 15) +
    labs(y = "Latitude", x = "Longitude", fill = "Elevation") +
    coord_cartesian(expand = 0)+
    ggtitle("A marmap map with ggplot2") 
库(marmap);图书馆(GG2)
图书馆(marmap)

这样洗澡真的很好。我用更多信息编辑了我的问题。@Luca Stirnimann我建议再问一个问题,而不是编辑一个已经回答过的问题。
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()
library(marmap) ; library(ggplot2)

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

ctd <- data.frame(Longitude = c(37.5, 38, 38.5), Latitude = c(-47, -46.5, -46))

autoplot.bathy(Bathy, geom=c("tile","contour")) +
    scale_fill_gradient2(low="dodgerblue4", mid="gainsboro", high="darkgreen") +
    geom_point(data = ctd, aes(x = Longitude, y = Latitude),
               colour = 'black', size = 3, alpha = 1, shape = 15) +
    labs(y = "Latitude", x = "Longitude", fill = "Elevation") +
    coord_cartesian(expand = 0)+
    ggtitle("A marmap map with ggplot2") 
# Creating color palettes
blues <- c("lightsteelblue4", "lightsteelblue3", "lightsteelblue2", "lightsteelblue1")
greys <- c(grey(0.6), grey(0.93), grey(0.99))

# Plot
plot(Bathy, image = TRUE, land = TRUE, n=30, lwd = 0.1, bpal = list(c(0, max(Bathy), greys), c(min(Bathy), 0, blues)), drawlabels = TRUE)

# Add coastline
plot(Bathy, deep = 0, shallow = 0, step = 0, lwd=2, add = TRUE)

# Add stations
points(ctd, pch=15, cex=1.5)