本文介绍了使用Knitr时如何旋转多张图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用针织品作图.我想将其中一个旋转90度.例如:
I am using knitr with plots. I would like to rotate one of them 90 degree. For example:
\documentclass{article}
\begin{document}
<<cache=TRUE, echo=FALSE, message=FALSE, warning=FALSE, comment=NA, eval=TRUE, results=asis>>=
library("ggplot2")
library("gridExtra")
func <- function(data,x,y) {
p1 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
p2 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
p3 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
p4 <- ggplot(data.frame(data), aes(x = x, y = y)) + geom_point()
grid.newpage()
pushViewport(viewport(width = .9, height = .9,layout = grid.layout(nrow=2, ncol=2)))
print(p1,vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(p2,vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(p3,vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(p4,vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
grid.newpage()
pushViewport(viewport(width = .8, height = .5,layout = grid.layout(nrow=1, ncol=2)))
print(p1,vp = viewport(layout.pos.row = 1, layout.pos.col = 1))
print(p2,vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
}
x <- runif(20,0,1)
y <- rnorm(20)
test <- cbind(x,y)
func(test,x=test$x,y=test$y)
@
\end{document}
我想将第二页和图形都旋转90度.我知道我可以在一页上使用它:
I would like to rotate both the second page and the graph 90 degree. I know I can use this for one page:
\usepackage{pdflscape}
\begin{landscape}
....
\end{landscape}
但这两个图由grid.newpage()在一个函数中排列.我该如何实现?非常感谢!
But the two plots are arranged by grid.newpage() within one function. How can I achieve that? Thanks a lot!
推荐答案
我认为您可以在块选项中使用out.extra
:
I think you can use out.extra
in the chunk options:
来自knitr文档: http://yihui.name/knitr/options
From knitr docs: http://yihui.name/knitr/options
<<out.extra='angle=90', cache=TRUE, echo=FALSE, message=FALSE, warning=FALSE, comment=NA, eval=TRUE, results='asis'>>=
# ...
@
这篇关于使用Knitr时如何旋转多张图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!