【发布时间】:2016-03-13 10:30:59
【问题描述】:
我有一个两行图,它由第一行的图和第二行的图列表组成。
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 时吐出情节?
【问题讨论】:
-
我认为你应该改用
arrangeGrob。 -
@Axeman 这就是答案。
标签: r ggplot2 latex knitr do.call