[R] Equal confidence interval arrowhead lengths across multiple-paneled lattice plots with free y-scales
Bob Farmer
farmerb at gmail.com
Thu Nov 15 21:08:56 CET 2007
Hi.
I've got a lattice plot with multiple panels and two groups superimposed
on each panel. Each panel has an independently scaled y-axis (scales =
list(relation = "free")).
I've successfully put up 95%CI error bars using panel.arrows (and some
help from the mailing list). My question is whether I can "unscale" the
arrowheads so that they appear to have the same length across all panels.
I recognize from the help-file that the "length" argument in
panel.arrows is in terms of grid units (which I assume are specific to
the particular panel). Can anybody think of a way to set the length so
that it appears uniform across all panels?
Example code:
summTable<-data.frame("X" = seq(1,12), "Y" =
c(1,8,3,6,6,5,7,3,8,1,10,-2),
"Location" = rep(c("Site1", "Site2"), times = c(6,6)),
"Species" = rep(c("A", "B"), 6)
)
#change scale for Site 1
summTable[1:6,2]<-100*summTable[1:6,2]
#arbitrary confidence intervals
summTable<-cbind(summTable, "ly" = (summTable$Y*(.98)),
"uy" = (summTable$Y*1.02)
)
#panel plotting
panel.func<-function(x,y,ly,uy,subscripts,...){
ly<-as.numeric(ly)[subscripts]
uy<-as.numeric(uy)[subscripts]
panel.arrows(x,ly,x,uy,
unit = "native",
angle = 90,
length = .25,
code = 3,
)
panel.xyplot(x,y,...)
}
xyplot(Y ~ X | Location, groups = Species,
type = "l",
data = summTable,
scales = list(relation = "free"),
ly = summTable$ly, uy = summTable$uy,
auto.key = T,
panel = panel.superpose,
panel.groups = panel.func
)
Thank you.
--Bob Farmer
(using R 2.6.0 and lattice 0.16-5)
More information about the R-help
mailing list