[R] grid graphics

Jeroen Van Houtte UCD jjvanhoutte at ucdavis.edu
Thu Jan 13 23:37:43 CET 2005


Thank you, Uwe,
I probably phrased my question wrong, but I'm not into compiling my own
software.

Thank you Martin,

It was definitely worth the few weeks spent learning to use the grid
package.
I want to share with others making that same step some of the functions I
wrote as I tried to convert from the graphics mindset to the grid.graphics
mindset.

gtext<-function(x=0.5,y=0.5,label="gtext()",adj=0.5){
	if(adj==1) {
	grid.text(x=x,y=y,default.units="native", label, just="right")
	} else {
	if(adj==0) {grid.text(x=x,y=y,default.units="native", label,just="left")
	} else {
	grid.text(x=x,y=y,default.units="native", label,just="center")
	}}}
glines<-function(x,y) grid.lines(x,y,default.units="native")
gpol<-function(x,y,fill=grey(0.5)) grid.polygon(c(x,x[1]),c(y,y[length(y)]),
	gp=gpar(fill=fill),default.units="native")
garrows<-function(){
	grid.arrows(x=c(0,105),y=0,length=unit(2,"mm"),angle=10,default.units="nati
ve")
	grid.arrows(x=0,y=c(0,105),length=unit(2,"mm"),angle=10,default.units="nati
ve")
	}
grect<-function(x,y,x2,y2) {
	grid.rect(x,y,x2-x,y2-y,
		default.units="native", just=c("left","bottom"))
	}

gbalk<-function(lijn=1,x1=0,x2=1,label=label){
	vp<-viewport(x = x1, y = lijn-1, w = x2-x1, h = 1,
		default.units="native", just = c("left", "bottom"))
	pushViewport(vp)
	grid.rect()
	grid.text(label) #(,x=0,just="right")
	popViewport()
	}

To see how I used these, look at
http://www.geocities.com/jjeroen1/cescompexample.R.txt


-----Original Message-----
From: Martin Maechler [mailto:maechler at stat.math.ethz.ch]
Sent: Monday, January 03, 2005 2:32 AM
To: Uwe Ligges
Cc: Jeroen Van Houtte; r-help at stat.math.ethz.ch
Subject: Re: [R] Error in layout(): Too many rows in layout

   >> I found that the limit of 15 is set by #define
    >> MAX_LAYOUT_ROWS 15

    UweL> Well, what about replacing 15 by something like 100?
    UweL> The point is that you should look where
    UweL> MAX_LAYOUT_ROWS is used for calculations and whether
    UweL> there might result any problem after increasing it.

    >> in
    >> https://svn.r-project.org/R/trunk/src/include/Graphics.h
    >> but I 'm not familiar enough with compilers to modify
    >> this.


Unless Jeroen is really keen on learning how build R from source
on MS Windows, I think Jeroen's time might be better invested in
learning to use the "grid" package instead of "graphics".

I think layout() in "graphics" is really just a poor man's
version of using layout.grid() and viewports as provided by the
"grid" package {and as used extensively by the "lattice" package}.

Martin Maechler




More information about the R-help mailing list