[R] Lattice device page options-margins

Paul Murrell p.murrell at auckland.ac.nz
Thu Mar 10 02:50:49 CET 2005


Hi


Bock, Michael wrote:
>  
> 
> 
>>-----Original Message-----
>>From: Deepayan Sarkar [mailto:deepayan at stat.wisc.edu] 
>>Sent: Wednesday, March 09, 2005 5:09 PM
>>To: r-help at stat.math.ethz.ch
>>Cc: Paul Murrell; Bock, Michael; Sundar Dorai-Raj
>>Subject: Re: [R] Lattice device page options-margins
>>
>>On Wednesday 09 March 2005 13:54, Paul Murrell wrote:
>>
>>>Hi
>>>
>>>Sundar Dorai-Raj wrote:
>>>
>>>>Bock, Michael wrote on 3/9/2005 1:19 PM:
>>>>
>>>>>I am using lattice to make figures as pdfs:
>>>>>trellis.device(device = "pdf",file = "Figure6.pdf",color = FALSE)
>>>>>
>>>>>I need to specify some blank space on the left-hand margins (the 
>>>>>pages will be bound so we need about 0.5 inch)). I have tried a 
>>>>>number of solutions but none seems to work (e.g. 
>>>>
>>par.set). Can this 
>>
>>>>>be done when initiating the plotting device? Or is the 
>>>>
>>some other 
>>
>>>>>way that does not require me to manually move everything over?
>>>>
>>>>Michael,
>>>>
>>>>I believe you can do this using print.trellis and setting the 
>>>>position argument. E.g.
>>>>
>>>>trellis.device(device = "pdf",file = "Figure6.pdf",color 
>>>
>>= FALSE) xy 
>>
>>>><- xyplot(...) print(xy, pos = c(0.10, 0, 1, 1))
>>>>dev.off()
>>>
>>>Or if you want exactly 0.5 inches, something like ...
>>>
>>># may need
>>># library(grid)
>>>trellis.device(device = "pdf",file = "Figure6.pdf",color = 
>>
>>FALSE) xy 
>>
>>><- xyplot(1:10 ~ 1:10) pushViewport(viewport(x=1,
>>>                       width=unit(1, "npc") - unit(0.5, "inches"),
>>>                       just="right"))
>>># to show region you're plotting in
>>># grid.rect(gp=gpar(col="grey"))
>>>print(xy, newpage=FALSE)
>>>popViewport()
>>>dev.off()
>>
>>Yet another option, especially if you want this for multiple 
>>plots without having to handle each one separately, is to say 
>>(after loading
>>lattice):
>>
>>lattice.options(layout.widths = list(left.padding = 
>>                list(x = 0.5, units = "inches")))
>>
>>Unlike par settings though, this would stay in effect across devices.
>>
>>Deepayan
>>
>>
> 
> Thanks for the suggestions. None of these do exactly what I want. I have
> some multi panel plotts
> Excepted Commands:
> BC.PP<-bwplot(PP.PAH ~ Area, Crab, horizontal = FALSE,
>         ylab = "Priority Pollutant PAHs (mg/kg)",
>         scales = list(x="free",rot=90),  aspect = 1.5,
>         main = list(label = "Blue Crabs",cex=0.8,font=1),
>         fontfamily = "HersheySans")
> RM.PP<-bwplot( PP.PAH ~ Area, Mussel, horizontal = FALSE,
>         ylab = "",
>         scales = list(x="free",rot=90), aspect = 1.5,
>         main = list(label="   Ribbed Mussels",cex =0.8,font=1),
>         fontfamily = "HersheySans")
> print(BC.PP, split = c(1,1,2,1), more = TRUE )
> print(RM.PP, split = c(2,1,2,1),more = TRUE )
> grid.text(label = "Figure 6. Priority Pollutant PAH Tissue
> Concentrations",
>           x = unit(0.01, "npc"), y = unit(0.1, "npc"),
>           just = "left", rot = 0,
>           check.overlap = FALSE, default.units = "npc",
>           name = NULL, gp = gpar(fontsize = 10, font = 2), draw = TRUE)
> grid.text(label = "Privileged and Confidential \nAttorney Work Product",
>           x = unit(0.01, "npc"), y = unit(0.95, "npc"),
>           just = "left", rot = 0,
>           check.overlap = FALSE, default.units = "npc",
>           name = NULL, gp = gpar(fontsize = 6, font = 3), draw = TRUE)
> 
> 
> All of the suggestions shrink the individual boxplots so they both now
> have empty space on the left size. I guess what I really want is to be
> able define the plotting area as a portion of the page, allowing for a
> blank region on the left. Basically defining the margin of the print
> area.
> 
> BSomething like:
> trellis.device(device = "pdf",file = "Figure6.pdf",color = FALSE,left =
> 0.1, right = 0.9)
> Assuming the hypothetical left and right commands set the print area for
> the pdf. Hopefully this better defines my "ideal solution".
> 
> Thanks for the suggestions, if an ideal solution can not be found I at
> least have enough to develop a work around.  It just too bad I hadn't
> though of this issue before writing so many scripts to make my plots
> that will now have to be adjusted manually.


Do you mean like this ...?

# Dummy data
# (it would be easier to give an answer if you gave us the real thing)
Crab <- data.frame(PP.PAH=rnorm(20),
                    Area=factor(sample(20, 1:2, replace=TRUE)))
Mussel <- data.frame(PP.PAH=rnorm(20),
                      Area=factor(sample(20, 1:2, replace=TRUE)))

BC.PP<-bwplot(PP.PAH ~ Area, Crab, horizontal = FALSE,
         ylab = "Priority Pollutant PAHs (mg/kg)",
         scales = list(x="free",rot=90),  aspect = 1.5,
         main = list(label = "Blue Crabs",cex=0.8,font=1),
         fontfamily = "HersheySans")
RM.PP<-bwplot( PP.PAH ~ Area, Mussel, horizontal = FALSE,
         ylab = "",
         scales = list(x="free",rot=90), aspect = 1.5,
         main = list(label="   Ribbed Mussels",cex =0.8,font=1),
         fontfamily = "HersheySans")
trellis.device(device = "pdf",file = "Figure6.pdf",color = FALSE)
# push viewport for ALL drawing
pushViewport(viewport(x=.1, width=.8, just="left"))
# just to show region you're plotting in
grid.rect(gp=gpar(col="grey"))
print(BC.PP, split = c(1,1,2,1), more = TRUE, newpage=FALSE)
print(RM.PP, split = c(2,1,2,1),more = TRUE)
grid.text(label = "Figure 6. Priority Pollutant PAH Tissue Concentrations",
           x = unit(0.01, "npc"), y = unit(0.1, "npc"),
           just = "left", rot = 0,
           check.overlap = FALSE, default.units = "npc",
           name = NULL, gp = gpar(fontsize = 10, font = 2), draw = TRUE)
grid.text(label = "Privileged and Confidential \nAttorney Work Product",
           x = unit(0.01, "npc"), y = unit(0.95, "npc"),
           just = "left", rot = 0,
           check.overlap = FALSE, default.units = "npc",
           name = NULL, gp = gpar(fontsize = 6, font = 3), draw = TRUE)
popViewport()
dev.off()


-- 
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