I am trying to place more than three tables on one page of a pdf using knitr and xtable. The following code places the fourth table on the second page. If they are size appropriate, is there a way to include all of the tables on one page?
The following example places the fourth table on the second page, although there appears to be room on the first page.
---
title: "Example Code"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(xtable.comment = FALSE)
library(xtable)
```
```{r t1, results='asis'}
xtable(cars[1:2,])
```
```{r t2, results='asis'}
xtable(cars[3:4,])
```
```{r t3, results='asis'}
xtable(cars[5:6,])
```
```{r t4, results='asis'}
xtable(cars[7:8,])
```
I think this is due to one of the settings like totalnumber or \textfraction explained here on TEX.SE. However, I couldn't come up with settings that place all four tables on one page so far.
Therefore, if the tables don't need to actually float, I suggest loading the float package and using the position specifier H:
---
title: "Example Code"
output: pdf_document
header-includes:
- \usepackage{float}
---
```{r setup, include=FALSE}
options(xtable.table.placement = "H")
library(xtable)
```
```{r t1, results='asis'}
xtable(cars[1:2,])
```
```{r t2, results='asis'}
xtable(cars[3:4,])
```
```{r t3, results='asis'}
xtable(cars[5:6,])
```
```{r t4, results='asis'}
xtable(cars[7:8,])
```
Related
I'm really looking for a guide on the layout of Slidy slides. Specifically, I'm trying to arrange plots and tables on a slide. I guess the flexdashboard example would look something like below:
---
title: "Min_Example"
author: "Brian Balzar"
date: "3/23/2022"
output: slidy_presentation
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Example Slide
## Row
### Equation
$$
a^2 + b^2 = c^2
$$
## Row
## Column 1
### Summary
```{r cars, echo = TRUE}
summary(cars)
```
## Column 2
### Chart
```{r plot}
plot(cars)
```
### Row
```{r table}
knitr::kable(cars)
```
I'm open to doing this in HTML, just need to know how to do it!
I've got a couple of charts that show two related data sets. I would like to have them appear in the same 'category' on the markdown, but under two separate 'subtitles' on the table of contents.
My YAML follows this pattern (though I have also used "toc:true" and "toc_float: true" previously):
---
title: "Update"
author: "Me"
date: "`r Sys.Date()`"
output:
rmdformats::readthedown:
fig_width: 12
fig_height: 5
---
The code I use to produce the charts in the markdown follows this format:
# Time-series
## Nominal
```{r chart1,echo=FALSE, cache=FALSE, warning=FALSE, message=FALSE, fig.height=25,fig.width=10}
Chart1
```
## Real
```{r chart2,echo=FALSE, cache=FALSE, warning=FALSE, message=FALSE, fig.height=25,fig.width=10}
Chart2
```
The 'category title' (Time-series) and 'subtitle' (Nominal) work as intended, and appear linked in the table of contents when the markdown is produced. The second 'subtitle' (Real) appears unlinked, and while it seems to recognise that 'Real' is intended to be a subtitle in RStudio, when the markdown html is produced it neither recognizes as a subtitle nor does it link it to the 'category title' above. Does anyone how to achieve this?
you are missing a blank line between chunk1 and ## Real
---
title: "Untitled"
author: "domingo"
date: "11 2 2022"
output:
html_document:
toc: TRUE
toc_float: TRUE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Time-series
## Nominal
```{r chart1,echo=FALSE, cache=FALSE, warning=FALSE, message=FALSE, fig.height=25,fig.width=10}
plot(mtcars)
```
## Real
```{r chart2,echo=FALSE, cache=FALSE, warning=FALSE, message=FALSE, fig.height=25,fig.width=10}
plot(mtcars)
```
I am preparing some slides in RMarkdown, and I need to plot the code on one slide and the plot on the next one, so I frequently find myself doing something on the lines of
```{r, eval=FALSE}
plot(x ,y)
````
---
```{r, echo=FALSE}
plot(x, y)
```
Is there a more elegant way to doing things that would avoid repetitions?
Instead of that create an object and call it
```{r}
plt <- plot(x ,y)
````
---
```{r, echo=FALSE}
plt
```
In case you would like to split all your plots over two frames:
---
output:
beamer_presentation:
keep_tex: true
header-includes:
- \renewenvironment{Shaded}{\begin{onlyenv}<.(1)>\begin{snugshade}}{\end{snugshade}\end{onlyenv}\pause}
---
```{r, include=TRUE}
plot(pressure)
```
I have been trying to plot a hierarchy tabs in R markdown but somehow when I knit the document it does not show the tabs. I was expecting: Score should have Plots and Plots123 as sub tab and Score1 should be aligned with Score tab. But my output does not show any tabs.
PS: (I have purposely written `` while defining a chunk because Stack overflow interprets '```' as code)
## Score {.tabset}
### Plots
``
{r pressure, echo=FALSE}
plot(pressure)
``
### Plots123
``{r pressure_1, echo=FALSE}
plot(pressure)
``
## Scores1 {.tabset}
``{r pressure_2, echo=FALSE}
plot(pressure)
``
Here's my version - this seems to work. Try this out exactly and let me know.
For rmarkdown, all sub-headers of the header with the .tabset attribute appear within tabs rather than as standalone sections. Also, trying additional spacing between headers.
---
title: "Test"
author: "Test"
date: "2/29/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Score {.tabset}
### Plots
```{r pressure, echo=FALSE}
plot(pressure)
```
### Plots123
```{r pressure_1, echo=FALSE}
plot(pressure)
```
## Scores1 {.tabset}
```{r pressure_2, echo=FALSE}
plot(pressure)
```
I'm trying to make a png image longer, but any setting I change has no effect. Following this, three different attempts are shown below. The options change the ggplot object in the last chunk properly. I am using RMarkdown and knitr.
```{r setup, include=FALSE, echo=FALSE}
knitr::opts_chunk$set(fig.width=9, fig.height=6)
library(RODBC)
library(data.table)
library(Matrix)
library(doParallel)
library(tidyverse)
library(gridExtra)
```
```{r , echo=FALSE, fig.height=50 }
knitr::include_graphics("data_sim_plot.png")
```
```{r , echo=FALSE, out.height=50, fig.height=50 }
knitr::include_graphics("data_sim_plot.png")
```
```{r , echo=FALSE, out.height=50, fig.height=50 }
knitr::opts_current$set(fig.height=20)
knitr::include_graphics("data_sim_plot.png")
```
```{r, echo=FALSE}
# a different ggplot object
readRDS("gg.rds")
```
```{r , echo=FALSE, out.width= "500px"}
knitr::include_graphics("index.jpg")
```{r , echo=FALSE, out.width= "800px" }
knitr::include_graphics("index.jpg")
They gave pictures with different length. Is this what you want?