[R] plotting x y z data from an irregular grid
erika
rikavons at hotmail.com
Thu Jul 14 15:39:18 CEST 2011
Hi,
I'm trying to plot some data (z) that is linked to lat&long coordinates
(x&y). These coordinates are not however on a regular grid. I also have some
shapefiles on which I would like to overlay the data. I can plot the
shapefiles (country/city outlines) and overplot the data, but only using
quilt.plot because I otherwise always get the error message that
'Error in image.default(..., add = add, col = col) :
increasing 'x' and 'y' values expected'
which has something to do with the organization of my data but I cannot
figure out how to change it correctly. This is the code that I have that
works:
data<-read.csv('with coord_observational log data trends all years all
data.8.11.10.csv', header=TRUE)
## this is what the 'data' looks like:
head(data)
X SiteCode Latitude Longitude p perc_per_year
perc_per_year_lower
1 1 A30 51.37357 -0.29172504 0.369164267 -0.4781589
-1.390382
2 2 BB1 51.68299 -0.03254972 0.005546354 -3.1810064
-5.665312
3 3 BG1 51.56375 0.17789100 0.000405606 -3.2260763
-5.344999
4 4 BG2 51.52939 0.13285700 0.434756172 -5.1558318
-22.123800
5 5 BH1 50.82334 -0.13724510 0.183375348 -0.8735160
-2.240289
6 6 BH2 50.82785 -0.17051300 0.002702969 -2.1443157
-3.543378
perc_per_year_upper sig
1 0.4786508 -999.000000
2 -0.8588293 -3.181006
3 -1.5251377 -3.226076
4 11.0957982 -999.000000
5 0.3431518 -999.000000
6 -0.7966338 -2.144316
#read in the shapefile
england<-readShapePoly('D:/arcGIS/england boundary/england.shp')
class(england)
#define the projection
proj4string(england)<-CRS('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.999601271625
+x_0=400000 +y_0=-100000 +ellps=airy +units=m +no_defs')
# transform the map into the WGS84 projection (epsg:4326):
england.wgs<-spTransform(england, CRS('+init=epsg:4326'))
plot(england.wgs)
#plot data over the map:
quilt.plot(data$Longitude, data$Latitude, data$perc_per_year, add=TRUE)
My problem is that I would like to be able to change how this data looks
(not just 'grid squares', but circles, etc) which I can't seem to do wtih
quilt.plot. If I could do this I could plot one layer of gridded data
(squares as in quilt.plot) and overlay a second layer of 'z' data as points.
I have tried plot.surface and image.plot and a number of others, but because
of the error message that I get above it won't work. I can use image.plot,
etc if I create a grid and interpolate my data onto the grid (see code
below), but I don't want interpolated data, I would like discreet values for
each lat&long.
x<-seq(-4,2, by=0.0625)
y<-seq(50,53, by=0.0625)
d1<-expand.grid(x=x, y=y)
data.li<-interp(data$Longitude, data$Latitude, data$perc_per_year,
duplicate='mean')
So my questions are, (1) is there a different function that I should be
using with my data as it is and still be able to overplot it onto the map
that i've plotted? or (2) is there a way to create this grid and integrate
my data into the grid, but not interpolate it?
Any help would be very much appreciated. My R skills just are not good
enough to do this yet.
Thank you!!
Erika.
--
View this message in context: http://r.789695.n4.nabble.com/plotting-x-y-z-data-from-an-irregular-grid-tp3667605p3667605.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list