[R] Lattice package - Trellis

David Winsemius dwinsemius at comcast.net
Thu Oct 15 16:39:26 CEST 2009


Perhaps you've not read FAQ:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

--  
David
On Oct 15, 2009, at 10:18 AM, Paul Evans wrote:

> Hi,
>
> I was trying to make a graph using trellis, and my code is:
> -----------------------------------------------------------------
> library(lattice)
>
> makeGraph <- function(){
>
>  trellis.device()
>  tbg <- trellis.par.get("background")
>  tbg$col <- "white"
>  trellis.par.set("background",tbg)
>
>  # Test Data
>  mfr <- matrix(sample(1:100,50,replace=T),ncol=2)
>  mfr <- cbind(mfr,c(rep(1,12),rep(2,13)))
>  mfr <- cbind(mfr,c(rep("All",6),rep("Reduced",6),rep("All", 
> 7),rep("Reduced",6)))
>  colnames(mfr) <- c("PVAL","POSITION","CHR","METHOD")
>  mfr <- as.data.frame(mfr)
>
>  pdf(file='test.pdf')
>  op <- par(no.readonly=TRUE)
>  xyplot(as.numeric(as.vector(PVAL)) ~  
> as.numeric(as.vector(POSITION)) | CHR, data = mfr, groups = METHOD,  
> ylab = "pval", xlab = "position",
>    type="p",col=c("green","red")
>  )
>  par(op)
>  dev.off()
> }
>
> makeGraph()
> _______________________________________________________
>
> However, when I execute the code I don't get the graph. Although a  
> pdf is generated, it is only 1 KB and when I try to open the pdf a  
> message comes up that says there are no pages in the pdf.  
> Interestingly, if I take the code (i.e. from line 'trellis.device()'  
> to line 'dev.off') out of the function call and execute it, the pdf  
> is generated just fine.
> What am I doing wrong?
> thanks!
>
> __________________________________________________
>
>
>
> 	[[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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list