Reputation: 63
I'm trying to interpolate my irregularly spaced set of points at the following coordinates which represent PM concentrations and then produce a contour map which represents PM concentration throughout the area. I used interp2xyz of AKIMA to interpolate but notice those little triangular white spots on the contour map. Are they missing values from not being able to extrapolate using mean values? How do I fix those to produce smooth contour map?
library(tidyr)
library(dplyr)
library(ggplot2)
library(akima)
site <- c(1:20)
long <- c(171.2496,171.1985,171.2010, 171.2076, 171.2236,171.2165,171.2473,171.2448,171.2416,171.2243,171.2282,171.2344,171.2153,171.2532,171.2444,171.2443,171.2562,171.2330,171.2356,171.2243)
lati <- c(-44.40450,-44.38520,-44.38010,-44.38530,-44.38750,-44.39195,-44.41436,-44.38798,-44.38934,-44.37958,-44.37836,-44.37336,-44.37909,-44.40801, -44.40472,-44.39558,-44.39919,-44.40971,-44.39577,-44.39780)
PM <- c(57,26,12,39,44,48,31,44,46,33,29,12,29,51,50,43,28,40,45,33)
fixed <- cbind(site,long,lati,PM)
### interpolate from fixed monitors
interpdf <-interp2xyz(interp(x=fixed$long, y=fixed$lati, z=fixed$PM, duplicate="mean"), data.frame=TRUE) %>%
filter(!is.na(z)) %>%
tbl_df()
ggplot(interpdf, aes(x=x,y=y,z=z, fill=z)) +
geom_contour(binwidth = 0.0005, aes(color= ..level..)) +
scale_color_distiller("PM", palette = "Spectral", limits = c(0, 70)) +
theme_bw()
Upvotes: 0
Views: 1152
Reputation: 1079
akima::interp
is creating a grid from irregular points by interpolating values for unknown locations from known locations. This function puts the results on a grid that the user can define. In your example you do not define a grid so, as the function help indicates:
The default is 40 points evenly spaced over the range of x.
You would like a smooth grid. This is done a number of ways. Interpolate higher resolution values on the screen or in the data.
Hijmans describes a few methods here:
https://gis.stackexchange.com/a/152533/19056
Or you can also increase the resolution parameters of the interp
function.
Upvotes: 1