我有两个netcdf文件: -每个网格(COL,ROW,LAY,TSTEP)的空气质量值(z值或填充值)记录 https://drive.google.com/open?id=1SHnmzV4L1Lqjj9XMdIFQ-nQHOGRpnPhB 每个网格的经度和纬度 https://drive.google.com/open?id=1dvsh2Ct2--3Bvcux4EXoRm0ntzAVx9OW
我想根据这些信息在地图上绘制地图。
经度和纬度不在计算区间内。
我尝试提取部分数据并使用ggplot + geom_raster 但是结果却不是我期望的
我还尝试将整个数据与geom_tile和geom_polygon一起使用,但未绘制图块
library(ncdf4)
#path and file
path <- "C:/Users/jhuang/Documents"
file <- "emis_mole_all_20060801_12US1_cmaq_cb05_tx_C25_2006am.ncf"
GRID <- "GRIDCRO2D_Benchmark"
#pollutant interested
poll <- "SO2"
file1 <- sprintf("%s/%s",path, file)
file2 <- sprintf("%s/%s",path, GRID)
ncin <- nc_open(file1)
gridin <- nc_open(file2)
#extract LAT and LON and also SO2 concentrations for each grid
LAT <- ncvar_get(gridin,"LAT")
LON <- ncvar_get(gridin,"LON")
data <- ncvar_get(ncin,poll)
library(ggplot2)
library(maps)
library(ggmap)
#extract first time step
data_1 <- data[,,1]
#organize all data into one data frame
data_2 <- data.frame(cbind(as.vector(LON),as.vector(LAT),as.vector(data_1)))
colnames(data_2) <- c("LON","LAT","POLL")
us_states <- map_data("state")
ggplot(data = data_2, aes(x=LON,y=LAT,fill=POLL)) +
geom_tile()+
geom_polygon(data=us_states,aes(x=long, y=lat, group=group), colour="black", fill="red", alpha=0)
我希望看到https://imgur.com/a/q9uD0gh。我可以使用NCL制作此图,只是想知道是否有可能在R中制作类似的图。