Re: [R] How to use the function "plot" as Matlab

From: Paul Murrell <>
Date: Mon 18 Jul 2005 - 10:18:37 EST


Peter Dalgaard wrote:

> (Ted Harding) <> writes:

>>This is definitely a case where "dynamic rescaling" could save
>>hassle! Brian Ripley's suggestion involves first building a
>>matrix whose columns are the replications and rows the time-points,
>>and Robin Hankin's could be easily adapted to do the same,
>>though I think would involve a loop over columns and some very
>>long vectors.
>>How much easier it would be with dynamic scaling!
> Cue grid graphics... (and Paul's new book)

... which will give you the basic tools to produce something like this.   Here's a very simple start at one possible way to do it (no argument checking, assumes x-values are 1:length(y-values), always plots points, quickly runs out of different symbols to use, pays no heed to efficiency, ...):

plotVPs <- function(x) {

   vpStack(plotViewport(c(5, 4, 4, 2), name="pvp"),

           # Calculate scale ranges based on ALL data
           dataViewport(1:max(unlist(lapply(x, length))),
                        unlist(x), name="dvp"))

drawDetails.scalePlot <- function(x, recording) {



   # Plot ALL data
   for (i in 1:length(x$data)) {
     xx <- 1:length(x$data[[i]])
     yy <- x$data[[i]]
     grid.lines(xx, yy, default.units="native",
     grid.points(xx, yy, pch=i,


scalePlot <- function(x, name=NULL, newpage=TRUE) {

   if (newpage)
   grid.draw(grob(data=list(x), name=name,



addPoints <- function(x, plot) {

   grid.edit(plot, data=c(grid.get(plot)$data, list(x))) }

# Testing

scalePlot(1:10, "myplot")
addPoints(2*1:100, "myplot")
addPoints(20*sin(seq(0, 3*pi, length=50)), "myplot")


Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
New Zealand
64 9 3737599 x85392

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Mon Jul 18 10:24:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:46 EST