Draw Symbols (User Defined) on a Lattice Plot
panel.mysymbols.RdThis function draws symbols on a lattice plot. It is similar to
the builtin symbols function with the difference that it plots
symbols defined by the user rather than a prespecified set of
symbols.
Usage
panel.my.symbols(x, y, symb, inches=1, polygon=FALSE,
..., symb.plots=FALSE, subscripts, MoreArgs)Arguments
- x, y
The
xandycoordinates for the position of the symbols to be plotted. These can be specified in any way which is accepted byxy.coords.- symb
Either a matrix, list, or function defining the symbol to be plotted. If it is a matrix or list it needs to be formatted that it can be passed directly to the
llinesfunction. It then defines the shape of the symbol on on a range/domain of -1 to 1. If this is a function it can either return a matrix or list as above (points on the range/domain of -1 to 1).- inches
The size of the square containing the symbol in inches (note: unlike
symbolsthis cannot beFALSE).- polygon
If TRUE, use
lpolygonfunction to plot rather than thellinesfunction.- symb.plots
Currently not implemented.
- ...
Additional arguments will be replicated to the same length as
xthen passed tosymb(ifsymbis a function) and/or thelinesfunction (one value per symbol drawn).- subscripts
subscripts for the current panel
- MoreArgs
A list with any additional arguments to be passed to the
symbfunction (as is, without being replicated/split).
Details
The symb argument can be a 2 column matrix or a list with
components 'x' and 'y' that defines points on the interval [-1,1] that
will be connected with lines to draw the symbol. If you want a closed
polygon then be sure to replicate the 1st point as the last point or
use the polygon option.
If any point contains an NA then the line will not be drawn to or from that point. This can be used to create a symbol with disjoint parts that should not be connected.
If symb is a function then any unmatched
arguments that end up in the '...' argument will be replicated to the
same length as 'x' (using the rep function) then the values
will be passed one at a time to the symb function. If
MoreArgs is specified, the elements of it will also be passed
to symb without modification. The symb function can
either return a matrix or list with the points that will then be
passed to the llines function (see above).
Author
Greg Snow 538280@gmail.com
Note
Plotting coordinates and sizes are based on the size of the device at the time the function is called. If you resize the device after plotting, all bets are off.
Examples
if(require(lattice)) {
tmpdf <- data.frame( x=1:10, y=1:10, g=factor(rep( c("A","B"), each=5 )),
z=c(1:5,5:1) )
xyplot( y ~ x, tmpdf, panel=panel.my.symbols, symb=ms.female, inches=0.3 )
xyplot( y ~ x | g, tmpdf, panel=panel.my.symbols, symb=ms.male, inches=0.3)
xyplot( y ~ x, tmpdf, panel=panel.superpose, groups=g,
panel.groups= function(group.number, ...) {
if(group.number==1) {
panel.my.symbols(..., symb=ms.male)
} else {
panel.my.symbols(..., symb=ms.female)
} },
inches=0.3
)
xyplot( y ~ x, tmpdf, panel=panel.my.symbols, symb=ms.polygram, n=tmpdf$z,
inches=0.3)
xyplot( y ~ x | g, tmpdf, panel=panel.my.symbols, symb=ms.polygram,
n=tmpdf$z, inches=0.3)
xyplot( y ~ x, tmpdf, panel=panel.superpose, groups=g,
panel.groups = panel.my.symbols,
inches=0.3, symb=ms.polygon, n=tmpdf$z, polygon=TRUE,
adj=rep(c(0,pi/4),5)
)
}
#> Loading required package: lattice