[R] PLotting R graphics/symbols without user x-y scaling

Paul Murrell p.murrell at auckland.ac.nz
Tue Feb 27 00:14:52 CET 2007


Hi


Jonathan Lees wrote:
> Is it possible to add lines or other
> user defined graphics
> to a plot in R that does not depend on
> the user scale for the plot?
> 
> For example I have a plot
> plot(x,y)
> and I want to add some graphic that is
> scaled in inches or cm but I do not want the
> graphic to change when the x-y scales are
> changed - like a thermometer, scale bar or
> other symbol -
> How does one do this?
> 
> I want to build my own library of glyphs to add to plots
> but I do not know how to plot them when their
> size is independent of the device/user coordinates.
> 
> Is it possible to add to the list
> of symbols in the function symbols()
> other than:
>   _circles_, _squares_, _rectangles_, _stars_, _thermometers_, and
>       _boxplots_
> 
> can I make my own symbols and have symbols call these?


There is currently no mechanism for defining your own additions to
symbols(), but this sort of thing is easily doable using the grid
graphics system, and the resulting symbols would be easy to add to
lattice plots.  See ...
http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter4.pdf
http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter5.pdf

There is also an example of how to do this sort of thing using the
grImport package (and grid and lattice) in
http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf
The complete code for the example is ...

library(grImport)
hourglass <-
     new("Picture",
         paths=
         list(new("PictureFill",
                  x=c(0, 1, 0, 1),
                  y=c(0, 0, 1, 1),
                  rgb="black"),
              new("PictureStroke",
                  x=c(0, 1, 0, 1, 0),
                  y=c(0, 0, 1, 1, 0),
                  rgb="grey")),
         summary=
         new("PictureSummary",
             numPaths=1,
             xscale=c(0, 1),
             yscale=c(0, 1)))
dotplot(variety ~ yield | year, data=barley,
         panel=function(x, y, type, ...) {
             panel.dotplot(x, y, type="n", ...)
             grid.symbols(hourglass,
                          x=unit(as.numeric(x), "native"),
                          y=unit(as.numeric(y), "native"),
                          size=unit(5, "mm"))
         })

Paul


> Thanks-
> 
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list