Rotate stargazer table in knitr
Asked Answered
B

1

2

I am using knitr to write a .Rnw file and the stargazer packages to build tables for regression outputs. For the most part it is working quite well but I would like to rotate a table 90 degrees like I would easily be able to do in LaTeX using \usepackage{sidewaystable} outside of .Rnw

\documentclass{article}

\begin{document}

<<table1, echo=FALSE, message=F, warning=F, results="asis">>=
library(stargazer)
lm1 <- lm(mpg ~ wt, data = mtcars)
lm2 <- lm(mpg ~ hp, data = mtcars)
lm3 <- lm(mpg ~ cyl, data = mtcars)
lm4 <- lm(mpg ~ disp, data = mtcars)

stargazer(lm1, lm2, lm3, lm4, title = "Basic OLS Models", omit.stat = c("f",    "ser"))
@
\end{document}
Bhagavadgita answered 1/7, 2015 at 19:18 Comment(0)
S
6

You can do this with the option float.env = "sidewaystable" in stargazer()

\documentclass{article}
\usepackage{rotating, graphicx}
\begin{document}

<<table1, echo=FALSE, message=FALSE, warning=FALSE, results=tex>>=
library(stargazer)
lm1 <- lm(mpg ~ wt, data = mtcars)
lm2 <- lm(mpg ~ hp, data = mtcars)
lm3 <- lm(mpg ~ cyl, data = mtcars)
lm4 <- lm(mpg ~ disp, data = mtcars)

stargazer(lm1, lm2, lm3, lm4, 
          title = "Basic OLS Models", 
          omit.stat = c("f",    "ser"),
          float.env = "sidewaystable")
@
\end{document}
Scrawly answered 15/12, 2015 at 14:53 Comment(3)
This works. Though the operative part is also to use the rotating package.Giselegisella
What version of everything are you using?Aspirator
TexLive 2017, R 3.5.1, Stargazer 2.2.2. I just edited the results argument in the answer, since the last one was outdated, but the rotating works fineScrawly

© 2022 - 2024 — McMap. All rights reserved.