Description Usage Arguments Author(s) Examples
Compare several plots and/or label placement methods. This creates a custom grid graphics display based on lattice and/or ggplot2 output. Plots will be on the columns and positioning methods will be on the rows.
1 2 |
plots |
List of ggplot2 or lattice plots. List names will be used to annotate the plot. |
pos.funs |
List of label placement methods to apply to each plot. List names, or function names if specified as character strings, will be used to annotate the plot. |
rects |
Draw rectangles around each plot, creating a grid? |
row.items |
If "plots" then put plots on the rows and method on the columns. Otherwise, do the opposite. |
debug |
Show debug output? |
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 | library(lattice)
library(ggplot2)
oldopt <- lattice.options(panel.error=NULL)
## Compare two plots of the same data using lattice and ggplot2.
dts <- cbind(male=mdeaths,female=fdeaths,time=1:length(mdeaths))
require(reshape2)
ddf <- melt(as.data.frame(dts),id="time")
names(ddf) <- c("time","sex","deaths")
plots <- list(lattice=
xyplot(deaths~time,ddf,groups=sex,type="l",xlim=c(-15,80)),
ggplot2=
qplot(time,deaths,data=ddf,colour=sex,geom="line")+xlim(-10,80))
if(names(dev.cur())!="postscript"){##to avoid error on pkg check Try
## Use some exotic labeling options with different rotation, font
## face, family, and alpha transparency.
exotic <- list("last.points",
rot=c(0,180),
fontsize=c(10,20),
fontface=c("bold","italic"),
fontfamily=c("mono","serif"),
alpha=c(0.25,1))
dlcompare(plots,list(exotic))
}
## Compare a legend with direct labels on the same plot.
library(nlme)
ggrat <- qplot(Time,weight,data=BodyWeight,
colour=Rat,geom="line",facets=.~Diet)
pfuns <- list("legend","direct labels"="last.qp")
dlcompare(list(ggrat),pfuns,rects=FALSE,row.items="posfuns")
lattice.options(oldopt)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.