quilt.plot | R Documentation |
Image plot for irregular spatial data.
Description
Given a vector of z values associated with 2-d locations this function produces an image-like plot where the locations are discretized to a grid and the z values are coded as a color level from a color scale.
Usage
quilt.plot(x, y, z, nx = 64, ny = 64,nrow=nx, ncol=ny, grid = NULL, add.legend=TRUE,add=FALSE,col=tim.colors(256),...)
Arguments
x |
A vector of the x coordinates of the locations -or- a a 2 column matrix of the x-y coordinates. |
y |
A vector of the y coordinates -or- if the locations are passed in x the z vector |
z |
Values of the variable to be plotted. |
nx |
Number of grid boxes in x if a grid is not specified. |
ny |
Number of grid boxes in y. |
nrow |
Number of grid boxes in x. |
ncol |
Number of grid boxes in y. |
grid |
A grid in the form of a grid list . |
add.legend |
If TRUE a legend color strip is added |
add |
If FALSE add to existing plot. |
col |
Color scale for the image, the default is tim.colors – a pleasing spectrum. |
... |
arguments to be passed to the image.plot function |
Details
This function combines the discretization to an image by the function as.image
and is then graphed by image.plot
. Locations that fall into the same grid box will have their z values averaged.
A similar function exists in the lattice package and produces good looking plots. The advantage of this fields version is that it uses the standard R graphics functions and is written in R code. Also, the aggregation to average values for z values in the same grid box allows for different choices of grids. If two locations are very close, separating them could result in very small boxes.
As always, legend placement is never completely automatic. Place the legend independently for more control, perhaps usingimage.plot
in tandem with split.screen
or enlarging the plot margin See help(image.plot)
for examples of this function and these strategies.
Author(s)
D.Nychka
See Also
as.image, image.plot, lattice, persp, drape.plot
Examples
data( ozone2) # plot 16 day of ozone data set quilt.plot( ozone2$lon.lat, ozone2$y[16,]) US( add=TRUE, col="grey", lwd=2) # # and ... if you are fussy # do it again # quilt.plot( ozone2$lon.lat, ozone2$y[16,],add=TRUE) # to draw over the state boundaries. # ### adding a common legend strip "by hand" ## and a custom color table coltab<- two.colors( 256, middle="grey50" ) par( oma=c( 0,0,0,5)) # save some room for the legend set.panel(2,2) zr<- range( ozone2$y, na.rm=TRUE) for( k in 1:4){ quilt.plot( ozone2$lon.lat, ozone2$y[15+k,], add.legend=FALSE, zlim=zr, col=coltab, nrow=40, ncol=40) US( add=TRUE) } par( oma=c(0,0,0,1)) image.plot(zlim=zr,legend.only=TRUE, col=coltab) # may have to adjust number of spaces in oma to make this work.
Results
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-unknown-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(fields) Loading required package: spam Spam version 0.29-3 (2013-04-23) is loaded. Type 'help( Spam)' or 'demo( spam)' for a short introduction and overview of this package. Help for individual functions is also obtained by adding the suffix '.spam' to the function name, e.g. 'help( chol.spam)'. Attaching package: 'spam' The following objects are masked from 'package:base': backsolve, forwardsolve Loading required package: maps > png(filename="/home/oogasawa/snapshot/RGM3/R_CC/result/fields/quilt.plot.Rd_%03d_medium.png", width=480, height=480) > ### Name: quilt.plot > ### Title: Image plot for irregular spatial data. > ### Aliases: quilt.plot > ### Keywords: hplot > > ### ** Examples > > > data( ozone2) > # plot 16 day of ozone data set > > quilt.plot( ozone2$lon.lat, ozone2$y[16,]) > US( add=TRUE, col="grey", lwd=2) > > # > # and ... if you are fussy > # do it again > # quilt.plot( ozone2$lon.lat, ozone2$y[16,],add=TRUE) > # to draw over the state boundaries. > # > > ### adding a common legend strip "by hand" > ## and a custom color table > > coltab<- two.colors( 256, middle="grey50" ) > > par( oma=c( 0,0,0,5)) # save some room for the legend > set.panel(2,2) plot window will lay out plots in a 2 by 2 matrix > zr<- range( ozone2$y, na.rm=TRUE) > > for( k in 1:4){ + quilt.plot( ozone2$lon.lat, ozone2$y[15+k,], add.legend=FALSE, + zlim=zr, col=coltab, nrow=40, ncol=40) + US( add=TRUE) + } > par( oma=c(0,0,0,1)) > image.plot(zlim=zr,legend.only=TRUE, col=coltab) > # may have to adjust number of spaces in oma to make this work. > > > > > > > dev.off() null device 1 >
![]() ![]() |