我有一个两行图,它由第一行的图和第二行的图列表组成。
我knitr
愿意
\documentclass{article}
\begin{document}
<<plots, fig.width='\\textwidth', echo = FALSE, fig.height=5, fig.width = 10, warning = FALSE>>=
require(ggplot2)
plot <- ggplot() + geom_point(data=cars, aes(speed, dist)) + labs(x=NULL, y=NULL)
# create plot with function
makePlot <- function(myLabel) {
ggplot() + geom_point(data=cars, aes(speed, dist)) + labs(x=NULL,y=NULL,title=myLabel)
}
list_plot <- lapply(c("one","two","three"), makePlot)
require(gridExtra)
grob <- do.call(grid.arrange, c(list_plot, nrow=1, ncol=3)) # here R sends the plots to the graphical device!
grid.arrange(plot,
grob,
nrow=3)
@
\end{document}
产生
问题是我do.call
的绘图列表,它立即将绘图发送到图形设备。
是否有解决此问题的方法,或者在将情节传递给时knitr
避免吐出情节?do.call
grob