Hi
I would like to be able to add reference lines to a series of plots that are
built using the Grid graphics package. These lines should coincide with tick
marks which are different on each plot.
I can add the lines manually using the grid.lines() function but would like
to understand how to generate them on the fly.
Any help would be gratefully received.
Kind regards
Pete
#######################################################################
# FUNCTION MYPLOT
#######################################################################
myplot=function(i,j){
pushViewport(viewport(layout.pos.col=i,layout.pos.row=j))
pushViewport(plotViewport(c(3,2,2,3)))
x <- runif(10)
y <- (i+j)*runif(10)
pushViewport(dataViewport(range(x),pretty(y),name="plotRegion"))
grid.points(x, y)
grid.rect()
grid.xaxis()
grid.yaxis(main=FALSE)
# How can I use grid.lines to create reference lines at the tick marks for
each graph?
# grid.lines(x=0:1,y=0.2)
grid.text(paste("Plot ",i," ",j,sep=""), y =
unit(1, "npc") + unit(0.5,
"lines"), gp = gpar(fontsize = 16))
popViewport()
popViewport(2)
}
#######################################################################
# END FUNCTION MYPLOT
#######################################################################
grid.newpage()
grid.rect(gp=gpar(fill="white"))
pushViewport(viewport(layout=grid.layout(2, 2)))
myplot(1,1)
myplot(1,2)
myplot(2,1)
myplot(2,2)
popViewport()
--
View this message in context:
http://r.789695.n4.nabble.com/Reference-Lines-Using-Grid-Graphics-tp3349185p3349185.html
Sent from the R help mailing list archive at Nabble.com.
Apologies .... I forgot to include that the reference lines should be for the y axis only. Thanks. Pete -- View this message in context: http://r.789695.n4.nabble.com/Reference-Lines-Using-Grid-Graphics-tp3349185p3349206.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Mar 11, 2011 at 4:50 PM, Pete Brecknock <Peter.Brecknock at bp.com> wrote:> Hi > > I would like to be able to add reference lines to a series of plots that are > built using the Grid graphics package. These lines should coincide with tick > marks which are different on each plot. > > I can add the lines manually using the grid.lines() function but would like > to understand how to generate them on the fly. > > Any help would be gratefully received. > > Kind regards > > Pete > > > ####################################################################### > # FUNCTION MYPLOT > ####################################################################### > myplot=function(i,j){ > ?pushViewport(viewport(layout.pos.col=i,layout.pos.row=j)) > ?pushViewport(plotViewport(c(3,2,2,3))) > > ?x <- runif(10) > ?y <- (i+j)*runif(10) > > ?pushViewport(dataViewport(range(x),pretty(y),name="plotRegion")) > > ?grid.points(x, y) > ?grid.rect() > ?grid.xaxis() > ?grid.yaxis(main=FALSE) > > ?# How can I use grid.lines to create reference lines at the tick marks for > each graph? > ?# grid.lines(x=0:1,y=0.2) > > ?grid.text(paste("Plot ",i," ",j,sep=""), y = unit(1, "npc") + unit(0.5, > "lines"), ?gp = gpar(fontsize = 16)) > ?popViewport() > ?popViewport(2) > } > ####################################################################### > # END FUNCTION MYPLOT > ####################################################################### > > > grid.newpage() > grid.rect(gp=gpar(fill="white")) > pushViewport(viewport(layout=grid.layout(2, 2))) > myplot(1,1) > myplot(1,2) > myplot(2,1) > myplot(2,2) > popViewport() >Try this: for(yy in pretty(y)) grid.lines(0:1, unit(yy, "native")) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Thanks Gabor. I owe you again. Kind regards Pete -- View this message in context: http://r.789695.n4.nabble.com/Reference-Lines-Using-Grid-Graphics-tp3349185p3349259.html Sent from the R help mailing list archive at Nabble.com.