[R] trellis.focus with postscript device
Hello. First: R 2.3.1 on Windows XP. I am trying to add information (sample size) to the Trellis strips which I am successful using the trellis.focus function with the default Windows device. However, I typically use the postscript device as I use LaTeX and \includegraphic for incorporating graphs into stat reviews. Here's some example code (apologies for the lack of creativity and resemblance to a real example) yy - c(rnorm(20,2),rnorm(35,3), rnorm(30,2),rnorm(20,3),rnorm(4,2), rnorm(10,3)) xx - c(1:20,1:35,1:30,1:20,1:4,1:10) gg - rep(c('A','B','A','B','A','B'), c(20,35,30,20,4,10)) pp - rep(c('Cond 1','Cond 2','Cond 3'), c(55, 50, 14)) xyplot(yy ~ xx | pp, groups=gg) trellis.focus('strip', 1, 1) ltext(0,.5,'20',col='red', pos=4) ltext(1,.5,'35',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 2, 1) ltext(0,.5,'30',col='red', pos=4) ltext(1,.5,'20',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 1, 2) ltext(0,.5,'4',col='red', pos=4) ltext(1,.5,'10',col='black', pos=2) trellis.unfocus() This works. But if I do, postscript('C:/TEMP/example.eps') # All code as above dev.off() I notice a problem with the graphic. When looking at the EPS figure, the only strip with added data is the first one (bottom left) with the strip still highlighted in red (i.e. it doesn't appear that trellis.unfocus() was executed). Work arounds that I can think of are to simply save the Windows device as postscript and save to the correct directory or better yet, write my own strip function. However, I was curious if there was another way using the strategy of postscript(), graph code, trellis.focus() code, dev.off(). Thanks, Mat *** Mat Soukup, Ph.D. Food and Drug Administration 10903 New Hampshire Ave. BLDG 22 RM 5329 Silver Spring, MD 20993-0002 Phone: 301.796.1005 *** [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] trellis.focus with postscript device
On 7/19/06, Soukup, Mat [EMAIL PROTECTED] wrote: Hello. First: R 2.3.1 on Windows XP. I am trying to add information (sample size) to the Trellis strips which I am successful using the trellis.focus function with the default Windows device. However, I typically use the postscript device as I use LaTeX and \includegraphic for incorporating graphs into stat reviews. Here's some example code (apologies for the lack of creativity and resemblance to a real example) yy - c(rnorm(20,2),rnorm(35,3), rnorm(30,2),rnorm(20,3),rnorm(4,2), rnorm(10,3)) xx - c(1:20,1:35,1:30,1:20,1:4,1:10) gg - rep(c('A','B','A','B','A','B'), c(20,35,30,20,4,10)) pp - rep(c('Cond 1','Cond 2','Cond 3'), c(55, 50, 14)) xyplot(yy ~ xx | pp, groups=gg) trellis.focus('strip', 1, 1) ltext(0,.5,'20',col='red', pos=4) ltext(1,.5,'35',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 2, 1) ltext(0,.5,'30',col='red', pos=4) ltext(1,.5,'20',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 1, 2) ltext(0,.5,'4',col='red', pos=4) ltext(1,.5,'10',col='black', pos=2) trellis.unfocus() This works. But if I do, postscript('C:/TEMP/example.eps') # All code as above dev.off() I notice a problem with the graphic. When looking at the EPS figure, the only strip with added data is the first one (bottom left) with the strip still highlighted in red (i.e. it doesn't appear that trellis.unfocus() was executed). Actually, you have produced a multiple-page postscript file, with what you really want in the last page. If you highlight the strips when calling trelis.focus, they have to be un-highlighted by trellis.unfocus. In theory, this is just a removal of a rectangle object. In practice, grid achieves this by drawing a new page. You need to avoid this. Your options are: (1) add 'highlight = FALSE' to all trellis.focus() calls (2) run the script in batch mode, where the default highlight = interactive() is FALSE I'll think about adding an option to control the default. Deepayan __ R-help@stat.math.ethz.ch 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.
Re: [R] trellis.focus with postscript device
It works fine as long as you give it the layout. I used xyplot(yy ~ xx | pp, groups=gg, layout=c(2,2)) This is needed to make sure that the rows and columns of the trellis that you reference are consistent with the layout that xyplot has chosen. Another way to handle this is to change the factor labels pp - factor(pp) levels(pp) - c(20 Cond 1 35, 30 Cond 2 20, 4 Cond 3 10) xyplot(yy ~ xx | pp, groups=gg) Rich __ R-help@stat.math.ethz.ch 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.
Re: [R] trellis.focus with postscript device
Thanks Deepayan. Adding the argument highlight=FALSE to each trellis.focus() call worked marvelously. Cheers, Mat -Original Message- From: Deepayan Sarkar [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 19, 2006 11:58 AM To: Soukup, Mat Cc: r-help@stat.math.ethz.ch Subject: Re: [R] trellis.focus with postscript device On 7/19/06, Soukup, Mat [EMAIL PROTECTED] wrote: Hello. First: R 2.3.1 on Windows XP. I am trying to add information (sample size) to the Trellis strips which I am successful using the trellis.focus function with the default Windows device. However, I typically use the postscript device as I use LaTeX and \includegraphic for incorporating graphs into stat reviews. Here's some example code (apologies for the lack of creativity and resemblance to a real example) yy - c(rnorm(20,2),rnorm(35,3), rnorm(30,2),rnorm(20,3),rnorm(4,2), rnorm(10,3)) xx - c(1:20,1:35,1:30,1:20,1:4,1:10) gg - rep(c('A','B','A','B','A','B'), c(20,35,30,20,4,10)) pp - rep(c('Cond 1','Cond 2','Cond 3'), c(55, 50, 14)) xyplot(yy ~ xx | pp, groups=gg) trellis.focus('strip', 1, 1) ltext(0,.5,'20',col='red', pos=4) ltext(1,.5,'35',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 2, 1) ltext(0,.5,'30',col='red', pos=4) ltext(1,.5,'20',col='black', pos=2) trellis.unfocus() trellis.focus('strip', 1, 2) ltext(0,.5,'4',col='red', pos=4) ltext(1,.5,'10',col='black', pos=2) trellis.unfocus() This works. But if I do, postscript('C:/TEMP/example.eps') # All code as above dev.off() I notice a problem with the graphic. When looking at the EPS figure, the only strip with added data is the first one (bottom left) with the strip still highlighted in red (i.e. it doesn't appear that trellis.unfocus() was executed). Actually, you have produced a multiple-page postscript file, with what you really want in the last page. If you highlight the strips when calling trelis.focus, they have to be un-highlighted by trellis.unfocus. In theory, this is just a removal of a rectangle object. In practice, grid achieves this by drawing a new page. You need to avoid this. Your options are: (1) add 'highlight = FALSE' to all trellis.focus() calls (2) run the script in batch mode, where the default highlight = interactive() is FALSE I'll think about adding an option to control the default. Deepayan __ R-help@stat.math.ethz.ch 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.