The Problem
When using rmarkdown in RStudio, my stargazer(glm())
output gets positioned below the text that I would like it to. It gets positioned in a different spot than the r chunk
is.
The PDF is created perfectly, it's just the position of the stargazer
output that is a problem.
Background
I am trying to create a PDF with lots of text and a couple of stargazer
glm()
output between a few of the paragraphs. When I put more than one stargazer()
output in my rmarkdown file and then "Knit" to PDF, the stargazer()
output gets moved down below the text.
I would like the stargazer output
to get positioned where I put the r chunks
.
I do not have the same problem when using inserting ggplot2()
output in a similar manner.
Failed Attempts
I have tried as many combinations as I know how of positioning my r chunks
arguments. (Just in case)
I have tried every combination of tab vs. spaces, before and after paragraphs/headers/r-chunks/etc. (That was a problem I had once with ggplot2 output)
I have referenced the following StackOverflow Questions:
Reproducible Example
A reproducible example of my work problem:
---
title: "Untitled"
author: "Me"
output: pdf_document
---
```{r setup, echo = FALSE}
library(stargazer)
mtcars_glm <- glm(formula = vs ~ disp + am + cyl + mpg, family = "binomial", data = mtcars)
```
# Heading1
I have tried creating paragraphs like this.
I have also tried creating paragraphs with 2 indents.
## Heading2
Lets try to create a couple of nice tables with stargazer.
```{r attempt1, results = 'asis', echo = FALSE}
stargazer(mtcars_glm, ci=FALSE, no.space = TRUE, report = c("vc*"), header = FALSE)
```
And then we will add some text down here, too.
```{r attempt2, results = 'asis', echo = FALSE}
stargazer(mtcars_glm, ci=FALSE, no.space = TRUE, report = c("vc*"), header = FALSE)
```
And some more text.
```{r attempt3, results = 'asis', echo = FALSE}
stargazer(mtcars_glm, ci=FALSE, no.space = TRUE, report = c("vc*"), header = FALSE)
```
Lets see what happens.
### Heading3
```{r plot_attempt}
boxplot(mtcars$mpg ~ mtcars$cyl)
```
# Second Section
## Second Header
Here are the 3 pages of output:
Page #1
Page #2
Page #3
Here is my sessionInfo:
R version 3.4.4 (2018-03-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] stargazer_5.2.1
loaded via a namespace (and not attached):
[1] compiler_3.4.4 backports_1.1.2 magrittr_1.5 rprojroot_1.3-2 htmltools_0.3.6 tools_3.4.4 yaml_2.1.19 Rcpp_0.12.16 stringi_1.1.7 rmarkdown_1.9
[11] knitr_1.20 stringr_1.3.0 digest_0.6.15 evaluate_0.10.1
Thanks
If you can help me, thanks. I do not know much about LaTeX or Pandoc, so I imagine it is some sort of knowledge gap. Feel free just to point me in the right direction, too, if you think you've found a solution.
I appreciate it.
See Question&Answers more detail:
os