[R] function to return plots
Naresh Gurbuxani
n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Fri Jun 12 11:52:28 CEST 2020
I want to write a function that will return lattice plots. This simple
function output a list of two plots. These plots can be
individually shown on the console. But I am unable to put them on two
panels of a single plot.
What changes do I need to make to this function?
Thanks,
Naresh
library(lattice)
getPlots <- function(){
x <- rnorm(1000)
plt1 <- histogram(x)
plt2 <- bwplot(x)
list(plt1, plt2)
}
plot.list <- getPlots()
plot.list[1] #Plots graph
plot.list[2] #Plots graph
plot(plot.list[1], position = c(0, 0, 1, 0.5), more = TRUE) #Error message
plot(plot.list[2], position = c(0, 0.5, 1, 1), more = FALSE) #Error message
## Plotting outside function works
x <- rnorm(1000)
plt1 <- histogram(x)
plt2 <- bwplot(x)
plot(plt1, position = c(0, 0, 1, 0.5), more = TRUE)
plot(plt2, position = c(0, 0.5, 1, 1), more = FALSE)
More information about the R-help
mailing list