Description Usage Arguments Author(s) Examples
Call panel.superpose for the data points and then for the direct labels. This is a proper lattice panel function that behaves much like panel.superpose.
1 2 3 |
x |
Vector of x values. |
y |
Vector of y values. |
subscripts |
Subscripts of x,y,groups. |
groups |
Vector of group ids. |
panel.groups |
To be parsed for default labeling method, and passed to panel.superpose. |
method |
Positioning Method for direct labeling. NULL indicates to choose a Positioning Method based on the panel.groups function. |
.panel.superpose |
The panel function to use for drawing data points. |
type |
Plot type, used for default method dispatch. |
debug |
passed to dlgrob. |
... |
passed to real panel function, and to translator. |
Toby Dylan Hocking
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | loci <- data.frame(ppp=c(rbeta(800,10,10),rbeta(100,0.15,1),rbeta(100,1,0.15)),
type=factor(c(rep("NEU",800),rep("POS",100),rep("BAL",100))))
## 3 equivalent ways to make the same plot:
library(lattice)
print(direct.label( ## most user-friendly
densityplot(~ppp,loci,groups=type,n=500)
))
print(direct.label( ## exactly the same as above but with specific panel fns
densityplot(~ppp,loci,groups=type,n=500,
panel=panel.superpose,
panel.groups="panel.densityplot")
))
## using panel.superpose.dl as the panel function automatically adds
## direct labels
print(densityplot(~ppp,loci,groups=type,n=500,
panel=panel.superpose.dl,panel.groups="panel.densityplot"))
## Exploring custom panel and panel.groups functions
library(ggplot2)
library(nlme)
## Say we want to use a simple linear model to explain rat body weight:
fit <- lm(weight~Time+Diet+Rat,BodyWeight)
bw <- fortify(fit,BodyWeight)
## lots of examples to come, all with these arguments:
ratxy <- function(...){
xyplot(weight~Time|Diet,bw,groups=Rat,type="l",layout=c(3,1),...)
}
## No custom panel functions:
##regular <- ratxy(par.settings=simpleTheme(col=c("red","black")))
regular <- ratxy()
print(regular) ## normal lattice plot
print(direct.label(regular)) ## with direct labels
## The direct label panel function panel.superpose.dl can be used to
## display direct labels as well:
print(ratxy(panel=panel.superpose.dl,panel.groups="panel.xyplot"))
print(ratxy(panel=function(...)
panel.superpose.dl(panel.groups="panel.xyplot",...)))
## Not very user-friendly, since default label placement is
## impossible, but these should work:
print(ratxy(panel=panel.superpose.dl,panel.groups=panel.xyplot,
method=first.points))
print(ratxy(panel=function(...)
panel.superpose.dl(panel.groups=panel.xyplot,...),
method=first.points))
## Custom panel.groups functions:
## This panel.groups function will display the model fits:
panel.model <- function(x,subscripts,col.line,...){
panel.xyplot(x=x,subscripts=subscripts,col.line=col.line,...)
llines(x,bw[subscripts,".fitted"],col=col.line,lty=2)
}
pg <- ratxy(panel=panel.superpose,panel.groups=panel.model)
print(pg)
## If you use panel.superpose.dl with a custom panel.groups function,
## you need to manually specify the Positioning Method, since the
## name of panel.groups is used to infer a default:
print(direct.label(pg,method="first.qp"))
print(ratxy(panel=panel.superpose.dl,panel.groups="panel.model",
method="first.qp"))
## Custom panel function that draws a box around values:
panel.line1 <- function(ps=panel.superpose){
function(y,...){
panel.abline(h=range(y))
ps(y=y,...)
}
}
custom <- ratxy(panel=panel.line1())
print(custom)
print(direct.label(custom))
## Alternate method, producing the same results, but using
## panel.superpose.dl in the panel function. This is useful for direct
## label plots where you use several datasets.
print(ratxy(panel=panel.line1(panel.superpose.dl),panel.groups="panel.xyplot"))
## Lattice plot with custom panel and panel.groups functions:
both <- ratxy(panel=panel.line1(),panel.groups="panel.model")
print(both)
print(direct.label(both,method="first.qp"))
print(ratxy(panel=panel.line1(panel.superpose.dl),
panel.groups=panel.model,method="first.qp"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.