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

From: Paul Murrell <p.murrell_at_auckland.ac.nz>
Date: Wed, 05 Nov 2008 16:03:46 +1300

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/

______________________________________________
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.
Received on Wed 05 Nov 2008 - 05:09:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Nov 2008 - 05:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive