[R] Combine two lattice plots including both plot keys
Naresh Gurbuxani
n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Sat Sep 5 16:28:23 CEST 2026
When I combine two lattice plots, only the first plot keys are
displayed. Is it possible to show both keys?
Thanks,
Naresh
library(data.table)
library(lattice)
library(latticeExtra)
mydt <- data.table(year = rep(2020:2025, 2), bird = rep(c("duck",
"goose"), c(6, 6)))
mydt[, let(popstart = 100 + sample(-10:10, 12, replace = TRUE), popend =
120 + sample(-10:10, 12, replace = TRUE))]
mydt[, let(flights = rep(seq(200, by = 10, length.out = 6), 2) +
sample(-20:20, 12, replace = TRUE))]
mydt1 <- copy(mydt)[, let(obspot = "lake")]
mydt2 <- copy(mydt)[, let(obspot = "river")]
mydt <- rbindlist(list(mydt1, mydt2))
mydtmelt <- melt(mydt, id.vars = c("year", "bird", "obspot"),
measure.vars = c("popstart", "flights"))
popbar <- mydtmelt[, barchart(value ~ as.character(year) | bird +
obspot, groups = variable, horizontal = FALSE, stack = TRUE, auto.key =
list(columns = 2, space = "bottom")) |> useOuterStrips()]
popdot <- mydt[, dotplot(popend ~ as.character(year) | bird + obspot,
type = "o", panel = function(x, y, ...){panel.dotplot(x, y, ...,
col.line = "transparent")}, key = simpleKey("popend", space = "top",
lines = TRUE, points = TRUE)) |> useOuterStrips()]
popbar # shows key at the bottom
popdot # shows key at the top
popbar + popdot # bottom key only
More information about the R-help
mailing list