[R] behaviour of plot(...,type="l")

Prof Brian D Ripley ripley at stats.ox.ac.uk
Mon Oct 23 21:18:33 CEST 2000


On Mon, 23 Oct 2000, Adrian Trapletti wrote:

> Brian, Peter,
> 
> Prof Brian Ripley wrote:
> 
> > > Date: Mon, 23 Oct 2000 14:49:54 +0200
> > > From: Adrian Trapletti <adrian at olsen.ch>
> > >
> > > plot(rnorm(100000),type="l")
> > >
> > > plots only about 7e4 lines while the same without type="l" works fine.
> > > Is this a feature or a bug or is this configurable?
> >
> > {on SunOS 5.5.1)
> >
> > We've seen this before (I thought there was a bug report on R-bugs,
> > but could not locate it quickly).
> 
> >
> > Assuming this is on an X11 device, it's a limitation of the X server.
> > Many (including Solaris ones) can only handle 64K line segments.
> 
> Yes I forgot to mention that it is on x11.
> 
> Nevertheless, if it's an x server limitation, then, at least the plotting
> programs I have tried here  --- gnuplot (octave), Spyglass Plot, probably
> also Splus (was not able to try that because our Splus server is currently
> down) --- are quite clever to avoid these problems, they can easily plot,
> e.g., time series of length 1e5.

Indeed. The idea needed is to split the DrawLines call into pieces of less
than 64K: the following in src/unix/X11/devX11.c does that

static void X11_Polyline(int n, double *x, double *y, int coords, DevDesc
*dd)
{
    XPoint *points;
    double devx, devy;
    int i, j;
    x11Desc *xd = (x11Desc *) dd->deviceSpecific;
    points = (XPoint *) C_alloc(n, sizeof(XPoint));

    for(i=0 ; i<n ; i++) {
	devx = x[i];  devy = y[i];
	GConvert(&devx, &devy, coords, DEVICE, dd);
	points[i].x = (int)(devx);
	points[i].y = (int)(devy);
    }

    SetColor(dd->gp.col, dd);
    SetLinetype(dd->gp.lty, dd->gp.lwd, dd);
    for(i = 0; i < n; i+= 10000-1) {
	j = n - i;
	j = (j <= 10000) ? j: 10000; /* allow for overlap */
	XDrawLines(display, xd->window, xd->wgc, points+i, j, 
CoordModeOrigin);
    }
...

Works for me on Solaris 2.7 (which previously exhibited the problem).
I'll commit this for 1.2.0.  It's not going to be perfect for e.g.
dashed lines, but I don't think people will notice a 1 in 10000 glitch.


Brian

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 mailing list