简体   繁体   中英

R: Create correlation map between spreadsheet and netcdf dataset

I am stuck and could not find a solution anywhere. I would like to create a simple correlation map such as this one between my data , which is basically a list/ excel spreadsheet of daily rainfall values from a certain location for the month of January 2010 and a netcdf dataset with daily rainfall values for West Africa for the same time period. The netcdf dataset TRMM is available here and can be downloaded by clicking on the blue link saying "netCDF". My spreedsheet data is from Accra, Ghana (lat:5.6N, lon:-0.22W) and looks like this:

- Date, Rainfall
- 2010-01-01, 5.5
- 2010-01-02, 3
- 2010-01-03, 0
- 2010-01-04, 7
- 2010-01-05, NA
- 2010-01-06, 0
- ...
- 2010-01-31, 4.5   

I loaded the netcdf file as a raster::brick , but I am not sure how to deal with my data from Ghana in order to calculate the correlation between both datasets.

The first step to solving a problem like this is to create a small example with simple data so that you get the understand the principle. For example:

# example data 
library(raster)
set.seed(424)
b <- brick(nrow=10, ncol=10, nl=100)
values(b) <- matrix(runif(100*100, max=100), 100, 100)   
rain <- runif(100, max=100)

# function to compute correlation between rain and RasterBrick values
fun <- function(x) cor(as.vector(x), rain)

# use the function with calc
r <- calc(b, fun)
plot(r)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM