[R] How to create margin area around a graphic made by xyplot

Paul Murrell p.murrell at auckland.ac.nz
Wed Nov 5 04:03:46 CET 2008


Hi


Dr. Alireza Zolfaghari wrote:
> Hi list,
> Does any body know how I can create a margin area around the graphic created
> by xyplot (the same thing we do using par in plot function)? I tried
> viewport, but does not work.


The trick is to assign the xyplot() result and then print it explicitly
(with newpage=FALSE), like this ...

# grid.newpage()
vp<- viewport(x=.1,y=.1,width=.6,height=.6,just=c("left", "bottom"))
pushViewport(vp)
myplot <- xyplot(1:10 ~ 1:10)
print(myplot, newpage=FALSE)

Paul


> Here is the code:
> 
> ==============================================
> require(grid)
> vp<- viewport(x=.1,y=.1,width=.6,height=.6,just=c("left", "bottom"))
> pushViewport(vp)
> plotDATA=data.frame(Loss=c(1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10),Level=c("AvgAll","AvgAll","AvgAll","AvgAll","AvgAll","AvgAll","AvgAll",
> "AvgAll","AvgAll","AvgAll","AvgAll","AvgAll","GUL","GUL","GUL","GUL","GUL","GUL","GUL","GUL"),Line=c(1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8))
> library(lattice)
> xyplot( Loss ~ Line, data=plotDATA,
> t="p",scales=list(relation="sliced",x=list(at = 1:12),y=list(at =
> 0:10,axs="i")),
>     panel=function(x,y,subscripts, groups,...){
>     panel.xyplot(subset(plotDATA, Level=="AvgAll")$Line,subset(plotDATA,
> Level=="AvgAll")$Loss ,col="black",lwd=3,origin=0,...)
>     panel.axis(side = "right",
> at=c(4,8),labels=c(200,400),outside=TRUE,ticks=TRUE,half=FALSE)
>     panel.barchart(subset(plotDATA,Level=="GUL" )$Line,
> subset(plotDATA,Level=="GUL" )$Loss,box.ratio=1,horizontal = FALSE,stack =
> TRUE,reference = TRUE,col="blue",border="blue")
>      }
>  )
> ================================================
> Thanks and regards,
> Alireza
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list