Question

Thanks to help from this website, I have now managed to write my code to interpolate weather station rainfall data onto a 1km grid and plot it using R. The final bit of code eliminates unwanted data and then it is plotted using quilt.plot. The data to be plotted (mydf.final) is a list of values with the following headings: index, easting, northing, rainfall and average rainfall. A sample of the data to be plotted looks like this if I execute dput:

dput(mydf.final(head, 10))

structure(list(easting = c(101000, 101000, 101000, 101000, 101000, 
101000, 101000, 101000, 101000, 101000), northing = c(740000, 
741000, 742000, 743000, 744000, 745000, 746000, 747000, 748000, 
749000), rainfall = c(40.0997151135538, 40.3344163486536, 40.5681562532368, 
40.8009001543464, 41.0326137107226, 41.2632629265481, 41.4928141651644, 
41.721234162219, 41.9484900390941, 42.1745493154662), saar = c(1081.62, 
1081.62, 1081.62, 1081.62, 1081.62, 1078.68, 1078.68, 1078.68, 
1078.68, 1078.68)), .Names = c("easting", "northing", "rainfall", 
"saar"), row.names = 4717:4726, class = "data.frame")

I can plot this data using:

quilt.plot(cbind(mydf.final$easting,mydf.final$northing),mydf.final$rainfall, add.legend=TRUE,nx=599,ny=1209,xlim=c(0,700000),ylim=c(0,1250000))

This gives me an image that I can't post as I don't have enough reputation points. Amyway, the plot is a map of the UK showing rainfall of different colours, with maximum rainfall showing red and minimum blue.

Although this is okay, I would like to do two things:

  1. Make sure all the rainfall data to be plotted is 0 or greater. Some of the rainfall data is negative value (e.g. -1) , so how can I change all negative values to 0 before plotting?

  2. Rather than use a colour range between minimum and maximum (blue to red), I want to bin the values so, for example, blue is 0mm to 5mm, light blue is 5mm to 10mm, yellow is 10mm to 20mm, red is greater than 30mm etc etc. Any ideas how I achieve this?

Was it helpful?

Solution

Stealing from Roman's idea, but using findInterval instead:

y<- mydf.final$rainfall  # simplify typing
ycuts <- findInterval(y,c(0,5,10,20,30,max(y)))
quilt.plot(yourxdata, y , col=c('blue','lightblue','yellow','purple','red')[ycuts], {the rest of your arguments})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top