Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize stargarzer table when type=HTML for ioslides in RStudio

I am new to using R Markdown to create slides presentations within RStudio. I haven't been able to find anything online that addresses my specific question. This was close, but I'm having the opposite problem, i.e. I am tyring to shrink HTML stargazer output to fit on a single slide. This question is basically the same but no answers yet. Any ideas? Here is a stylized example of my markdown code:

---
title: "test"
author: "Scott Murff"
date: "September 4, 2015"
output: ioslides_presentation
---

## Slide with R Code and Output

```{r, echo=FALSE, results='asis', eval=TRUE, warning=FALSE, message=FALSE}
library(stargazer)
data<-data.frame(y=rnorm(30),x1=rnorm(30), x2=rnorm(30), x3=rnorm(30), x4=rnorm(30))
fit1<-lm(y~x1,data)
fit2<-lm(y~x2,data)
fit3<-lm(y~x3,data)
fit4<-lm(y~x4,data)


stargazer(fit1, fit2, fit3, fit4, type='html')
```
like image 999
Scott Murff Avatar asked Oct 19 '22 03:10

Scott Murff


People also ask

How do you make a stargazer table smaller?

To adjust table size with stargazer, you can change the font size font. size= , make the Stargazer single row single. row = TRUE and change the space between columns column.

How do I embed code in R markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).

How do I knit code in r?

If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.

How do I embed a plot in R markdown?

You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.


1 Answers

In your context, I haven't find a direct way through the stargazer options yet, however here's a work around through the slide parameters :

  1. you can enable the smaller option by adding {.smaller} directly to the title :

    ## your slide title {.smaller}

Source : http://rmarkdown.rstudio.com/ioslides_presentation_format.html#visual-appearance

you can also center it by adding .flexbox and .vcenter :

## your slide title {.smaller .flexbox .vcenter}

Source : http://rmarkdown.rstudio.com/ioslides_presentation_format.html#advanced-layout

However you don't have a full control of the size.

2. I prefer the css option :

in the YAML add :

---
output:
  ioslides_presentation:
    css: styles.css
---

then in the styles.css file (that you should place in your presentation folder), you can put :

.reduced{
   font-size: 0.8em;
}

and send it back in the attribute of your title slide, and you're good :

## your slide title {.reduced}

source : http://rmarkdown.rstudio.com/ioslides_presentation_format.html#visual-appearance in the custom css paragraph

Your final html output is still self-contained and with the css file you can manage even more customization.

After that you'll be able to use with more effectively the stargazer arguments like single.row=TRUE or omit.table.layout if you want to pursue the customization of your stargazer table.

like image 97
Gwenaël Gouérou Avatar answered Oct 21 '22 17:10

Gwenaël Gouérou