R mapping filled.contour georeferencing interpolat

2019-08-13 04:56发布

问题:

I'm trying to make a map kind of like this, but with higher resolution, and less of a tile like appearance:

Which used this code:

samps <- read.csv("Petra_phytoplankton+POM_xydata_minusNAs_noduplicates.csv")   #my data for sampling sites, contains a column of "lat" and a column of "lon" with GPS points in decimal degrees

samps_test<-samps

x<-samps_test$longitude
y<-samps_test$latitude
z<-samps_test$d13C

## interpolation using akima
x0<-seq(min(x), max(x), length = 100)
y0<-seq(min(y), max(y), length = 100)
z.hat <- interp(x,y,z)

#plot
par(mar=c(4.1,4.1,1,1))
image.plot(z.hat)
map(add=TRUE, fill=TRUE)
points(samps_test$longitude,samps_test$latitude,pch=4) 

But I wanted to interpolate with higher resolution so I used filled.contour() to create this map:

As you can see, the map and raw data points are not plotting correctly....how do I fixed this? I have a feeling it is because the filled.contour() plot is not georeferenced (so not in the same coordinate system as the map and data points)...but how do I change this?

Code for the second map:

df <-read.table("Petra_phytoplankton+POM_xydata_minusNAs_noduplicates.txt",header=T)
attach(df)
names(df)
fld <- with(df, interp(x = longitude, y = latitude, z = d13C))

filled.contour.ungeoreferenced<-(filled.contour(x = fld$x,
                           y = fld$y,
                           z = fld$z,
                           color.palette =
                             colorRampPalette(c("blue", "green","yellow","orange","red")),
                           xlab = "Longitude",
                           ylab = "Latitude",
                           key.title = title(main = "d13C", cex.main = 1)))

map(add=TRUE, fill=TRUE)

points(samps_test$longitude,samps_test$latitude, pch=4) #not plotting in the same space

I also tried making this graph in ggplot with geom_tile but it didn't work?

Also, I realise this is probably another question, but at the moment I don't know how to change axes titles and the like as it doesn't seem to be plotting with the base plot package, so normal commands don't work.

FYI here is a subset of my dataset:

latitude    longitude   d13C
-65 -70 -27.7
-61 150 -32.2
-61 150 -28.3
-60 116 -26.8
-60 116 -24.7
-47 38  -24.8
-38 150 -20.5
19  -65.7   -19.9
19  -65.5   -18.5
18  -60.7   -20
18  -58.5   -18.2
18  -57.8   -19
17  -55.4   -18.6
17  -50.8   -18
17  -47.1   -18.3
17  -45.5   -19.4
16  -43.3   -17.9
15  -40.7   -18.5
14  -39.3   -19.9
12  -36.7   -19.9
12  -36.2   -19.9
11  -34.4   -19.2
10  -32 -18.5
9   -30.3   -19.3
8   -29.2   -19.4
7   -26.6   -18.2
7   -25.5   -19.3
6   23.9    -20
3   -21.3   -20.4

I checked out these help forums but they don't tell me how to convert my datapoints OR map into the same scaling as filled.contour does. Plotting a box within filled.contour plots in R?

Adding points to filled.contour function in R