Plots don't have the correct dimensions

I have a nc file with temperatures for the year 2000-2001 (downloaded from the NASA site: https://data.giss.nasa.gov/gistemp/maps/index_v4.html) and I want to create a map with it.

I manage to plot the file but failed to smooth it. I tried to follow this tutorial (Interpolating Gridded 3D Data to a finer scale) but I get stuck in the last line of code, where the graph is supposed to get smoothed. The main problem is that the map is generated but not with the correct dimensions and not in the right place (and it's also fliped).

Being an absolute beginner with R (less than 10 hours of coding with it), I have no ideas how to get over those problems. Here is the whole (and quite short) code. The real problem begins in the ## Smoothing section

## Mapping for 2000-2001

#Packages
require(fields)
require(ncdf4)
require(raster)

#File
f = nc_open("mUN.nc")

#Var
lat = ncvar_get(f, "lat")
lon = ncvar_get(f, "lon")
anom = ncvar_get(f, "TEMPANOMALY", start = c(1, 1), count = c(-1, -1))

#Plot
image.plot(lon, lat, anom)
map(add = T)
title("Anomalie de température pour l'année 2000-2001 
      comparé à la moyenne 1951-1980")

##Smoothing

# Creating the extent cible
ex = extent(c(-180, 180, -90, 90))

# Coarse raster (original)
ran = raster(anom)

#  Simulate the grid of a finer-scale raster:
hd = raster(ncol=1000, nrow=1000, ext=ex)

#  Resample the coarser raster to match finer grid:
hdr = resample(x=ran, y=hd, method="bilinear")

## Final plot
plot(ran)
plot(hdr)

The idea behind the code is to make the same map as the first image.plot() but smoother than the one generated

Many thanks for your assistance to a beginner in R !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.