Reputation: 1440
Some years ago I posted a question as to how to add a title to an R lattice plot with the solution suggested here. However, I'm wondering if there is now a way to use lattice to add an outer margin then add text to the margin. Some example code is below where I would like to have the title "Iris Histograms" at the top of the output plotting page. I'm also wondering if there is a way to move the main title on each plot down closer to the histogram?
tmp <- "Iris_Hsit.jpg"
jpeg(filename = tmp, width = 20, height = 20 , units = "cm",
pointsize = 5,bg = "white", res = 600, quality = 75)
pdd <-2
lattice.options(
layout.heights = list(bottom.padding =list(x = pdd), top.padding = list(x = pdd)),
layout.widths = list(left.padding = list(x = pdd), right.padding = list(x = pdd))
)
for(i in 1:4){
tmp <- histogram(~iris[ ,i], data = iris, aspect = 1,
main = list(names(iris)[i], cex = 2),
xlab = list(names(iris)[i]))
if(i <= 2){
plot(tmp, split = c(1, i, 2, 2), more = TRUE)
}else{
j <- i - 2
plot(tmp, split = c(2, j, 2, 2), more = TRUE)
}
}
dev.off()
Upvotes: 1
Views: 536
Reputation: 269654
Using c.trellis from latticeExtra we can do this:
library(latticeExtra)
do.call(c, lapply(iris[1:4], histogram, main = "Iris", xlab = ""))
giving:
or xyplot.list which also uses latticeExtra and gives the same output:
xyplot.list(iris[1:4], FUN = histogram, main = "Iris", xlab = "", y.same = FALSE)
Also with plain lattice itself one can do this:
histogram(~ values | ind, stack(iris[1:4]), main = "Iris", xlab = "")
Upvotes: 1