[R] Custom graphing : Which package (Base, Grid or Lattice package)
p.murrell at auckland.ac.nz
Wed May 15 04:09:06 CEST 2002
Here are some points that will hopefully be helpful to you ...
1. I don't think lattice is what you want at all. This provides
powerful high-level graphics functions -- base and grid provide
(different approaches to) the low-level stuff.
2. If you want a parent "frame" and child "windows" to be GUI widgets
then you need to look at something like R's tcltk capabilities (see
Peter Dalgaard. A primer on the R-Tcl/Tk package. R News, 1(3):27-31,
September 2001; http://cran.r-project.org/doc/Rnews/) or possibly the
(http://www.omegahat.org/RGtk/). I think this is currently the only way
you will get some of the features you want (e.g., "scrolling" windows).
3. Assuming you can live without true GUI widgets, ...
a) splitting a "page" into several bits can be done easily by either
base or grid -- see par(), esp. par(mfrow=), and layout() in base and
grid.layout(), viewport(), push.viewport() in grid.
b) for adding graphics to an existing plot, base graphics will let you
add more "ink" to the page, but does not retain "objects" representing
the output -- see lines() and points(). grid does create objects to
represent the output as well as adding more ink.
c) R's graphics engine (underlying both base and grid) retains a
display list so that when a window is resized the current output is
redrawn. This display list is a bit dumb and can get things wrong
d) R's graphics engine does not provide good access to user events
currently. You can get hold of mouse clicks, but only modally -- see
locator() and identify().
e) For zooming in and out, the main problems are: (i) user interface
-- you can only grab mouse clicks unless you develop something with the
gui tools. I can give you a simple mouse-click zoom example if you're
interested (ii) redraws -- R devices currently do not have
double-buffering so one-off redraws are pretty nasty, and multiple
redraws are a nightmare.
So after all that you may be wondering, does R graphics do anything
properly? Well, it tries to be hell-on-wheels for static, presentation
graphics. It is very weak on interactivity, but we have plans to try
and improve that. There are gui tools, such as tcltk, which might get
you the interactive bits you want.
In terms of choosing between base and grid, grid provides more
flexibility in the production of the graph itself, but it sounds like
you are producing pretty standard graphs so there is no reason to
On the other hand, it sounds like the features you are after are more
interaction-oriented and grid does have the advantage of producing
objects representing your output so that you have a chance to modify
those objects. With regard to documentation, there is a web page for
grid at http://www.stat.auckland.ac.nz/~paul/grid/grid.html and you
might be particularly interested in the "simple scatterplot" document.
Hope that's of some help.
> Over the years, I have written a number of custom time series graphing
> modules (in ANSI C). I want to make these graphs available in R. After
> considerable thought (as well as feedback fom this NG - thanks go to Don
> MacQueen and Paul Murrell), I have decided to re-write (atleast some of the
> routines in R).
> Basically, this is what my R function needs to do:
> 1. create a parent (container) frame
> 2. Define n (vertically stacked) child windows within the parent (where n is
> 1,2 or 3)
> So the object factory (creator function) would look something like this :
> custom.graph.create<- function (win1_perc_size, win2_perc_size, backcolor )
> where win*N_perc_size is the % of the HEIGHT of the parent screen assigned
> to the Nth child window
> The three child windows should share the same x axis (the calender date),
> but they would each have
> seperate y axis.
> In addition the returned object should;
> 1. allows you to add data to a specified window
> ( e.g. fooAddSeries(custom_graph_obj, dataset, child_win_number) )
> 2. Redraw the parent (and all children) when the parent window is resized
> 3. Be able to respond to mouse movements over a child window
> (so I can display info like date : value etc)
> 4. Be able to "scroll" through *LARGE* time series
> (approx 20,000 datapoints in certain cases) - using a "scrolling" window
> 5. Be able to "zoom in/out" to a specified granularity
> (daily, weekly etc) - maybe use the window function ?
> As I'm sure you'll appreciate, this is a lot of work, and before I actually
> sat down to do some coding, I thought it would be prudent to solicit some
> advice from someone who had done something similar or had experience with
> custom plotting/graphing in R.
> I have learnt the hard way, that as far as R is concerened, it's very easy
> to waste several weeks re-inventing the wheel, since it is such a
> functionally rich environment.
> There appear to be several competing (but not entirely compatable)
> "graphing" packages/extensions for R. The base package, which seems to be
> the most robust, does not appear to have all the features I need (I may be
> wrong though ...), The grid package which appears to have the functionality,
> I need is not well documented, and is full of internal functions ..., and
> I'm not too sure about the lattice package.
> I would be most grateful for any help on:
> 1. Recommendation on which package to use (base, grid or lattice ?)
> 2. General guidline (pref with skeleton code/stubs) on
> how to proceed - I haven't written any graphing functions in R before !
> 3. Pointers to more information
> Many Thanks in Advance
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help