s-news
[Top] [All Lists]

Re: Formatting trellis graphics - SUMMARY

To: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
Subject: Re: Formatting trellis graphics - SUMMARY
From: "Riley, Steve" <Steve.Riley@pfizer.com>
Date: Tue, 23 Aug 2005 06:56:56 -0400
I would like to extend my gratitude to Sundar Dorai-Raj, Max Zhao, Richard Heiberger, and Madeline Bauer for their suggestions and comments. Richard proposed the most comprehensive solution for what I was trying to achieve. I concur that for multi-panel plots, the additional axes are useful. However, I there are instances where trellis graphics are the most efficient to code, even when there is only a single panel, and my preference is to exclude the unnecessary axes in those cases.  I have included all of the responses and my original posting below. Thanks again for taking the time to respond to my query!
 
Steve
Madeline provided the following comment:

I agree with Rich that the boxes add to the plot. If one really wants to eliminate sides of the panel box, perhaps it would improve the graph to use the between parameter to insert horizontal space between the panels.

Madeline

Richard's solution:

You can get all that you are asking for from trellis.

But it looks bad if you have more than one panel. I will guess therefore that it is intentionally difficult to turn the box off. Here are three plots. the first is what you asked for.

The second and third show what happens with two panels.

Neither looks good.

As you can see, these are based on the previous responses to your query.

Rich

y <- c(1:10,1:10*2)

x <- c(rep(1:10,2))

id <- c(rep(1,10), rep(2,10))

trt <- rep(letters[1:2],5)

data <- cbind.data.frame(TIME = x, CONC = y, ID = id, treatment=trt)

par(bty="l") ## get the "L" shaped box

par(oma=c(4,2,2,2)) ## This is to control the outer margin.

xyplot(CONC ~ TIME, data = ""

groups = ID,

scale = list(x = list(draw = F), y = list(draw = F)),

xlab="", ylab="",

panel = function(x,y,subscripts,...) {

panel.superpose(x,y,subscripts,type="b",...)

axis(side=1, at=seq(2,10,2), labels=seq(2,10,2), font=2)

axis(side=2, at=seq(5,20,5), labels=seq(5,20,5), font=3, adj=1)

}

)

## Add x and y labels.

mtext("Time", side = 1, outer = F, font =2, cex = 1.2, line=6) mtext("CONC", side = 2, outer = F, font =2, cex = 1.2, line=5) mtext(side=3, "This is how it looks with one panel.", outer=T)

 

xyplot(CONC ~ TIME | treatment, data = ""

groups = ID,

scale = list(x = list(draw = F), y = list(draw = F)),

xlab="", ylab="",

panel = function(x,y,subscripts,...) {

panel.superpose(x,y,subscripts,type="b",...)

axis(side=1, at=seq(2,10,2), labels=seq(2,10,2), font=2)

axis(side=2, at=seq(5,20,5), labels=seq(5,20,5), font=3, adj=1)

}

)

mtext(side=3, "This looks bad when there is more than one panel.", outer=T)

 

par(bty="o") ## restore the "O" shaped box xyplot(CONC ~ TIME | treatment, data = ""

groups = ID,

scale = list(x = list(draw = F), y = list(draw = F)),

xlab="", ylab="",

panel = function(x,y,subscripts,...) {

panel.superpose(x,y,subscripts,type="b",...)

axis(side=1, at=seq(2,10,2), labels=seq(2,10,2), font=2)

axis(side=2, at=seq(5,20,5), labels=seq(5,20,5), font=3, adj=1)

}

)

mtext(side=3, "We now have excess tick labels.", outer=T)

Max responded with:

Steve,
 
Trellis Graphics is almost as flexible as the regular Splus in making the graphs.  There is an argument called "scale" for trellis functions such as xyplot, barchart etc.  You could turn off the axis completely, and using the axis to do the graph yourself, allowing you to make changes you need. Below is the code that will generate the graph you want.
 
Hope this help.
Max
 
####################################################
y <- c(1:10,1:10*2)
x <- c(rep(1:10,2))
id <- c(rep(1,10), rep(2,10))
data <- cbind.data.frame(TIME = x, CONC = y,ID = id)
 
trellis.device(graphsheet)
par(oma=c(4,2,2,2))                                            ##  This is to control the outer margin.
xyplot(CONC~TIME, data = ""
 groups = ID,
 scale = list(x = list(draw = F), y = list(draw = F)), xlab="",ylab="",
 panel = function(x,y,subscripts,...) {
  panel.superpose(x,y,subscripts,type="b",...)
  axis(side=1, at=seq(2,10,2), labels=seq(2,10,2),font=2)              ## Add the ticks with your font choices.
  axis(side=2, at=seq(5,20,5),labels=seq(5,20,5),font=3,adj=1)
 }
)
mtext("Time",side = 1, outer = F, font =2, cex = 1.2, line=6)        ### Add x and y labels.
mtext("CONC",side = 2, outer = F, font =2, cex = 1.2, line=5)
 

 

Sundar wrote:

Hi, Steve,

For question 1, try adding a scales list with your font argument.

For question 2, try adding alternating = FALSE. This may not do what you want since the tick marks are still there, but you do get more space than with the default.

xyplot(..., scales = list(font = 2, alternating = FALSE)))

HTH,

--sundar



From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Riley, Steve
Sent: Monday, August 22, 2005 11:29 AM
To: 's-news@lists.biostat.wustl.edu'
Subject: [S] Formatting trellis graphics

All,
 
I have a 2 questions regarding formatting of trellis graphics. Using the plot generated by the code below as an example, how might I, 1) change the font of the axis tick labels and 2) generate the plot without the top and right side axes. Using traditional graphics, these items are modifiable using par(font = 2, bty = 'l') but I have been unsuccessful in getting a similar result using trellis graphics. Any input from the group would be greatly appreciated! Thank you.
 
y <- c(1:10,1:10*2)
x <- c(rep(1:10,2))
id <- c(rep(1,10), rep(2,10))
data <- cbind.data.frame(TIME = x, CONC = y,ID = id)
#
#    Set font for axis labels
#
add.text <- trellis.par.get("add.text")
add.text$font <- 2
trellis.par.set("add.text",add.text)
 
xyplot(CONC~TIME, data = "" groups = ID, panel = panel.superpose, type = 'b')
 

Steve Riley, Pharm.D., Ph.D.
Clinical Pharmacokinetics & Pharmacodynamics
Pfizer Global Research & Development
Mail Stop MS8260-2302
Eastern Point Road
Groton, CT 06340

Steve.Riley@pfizer.com
Tel:  (860) 686-1795
Fax: (860) 686-5672



LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
<Prev in Thread] Current Thread [Next in Thread>
  • Re: Formatting trellis graphics - SUMMARY, Riley, Steve <=