I have the following code chunks in R markdown that produce 2 plots with some text in between but the pdf output is just sending all plots to the bottom of the document. How can I make it so the Plot stays in the spot of the text where I want it to be?
---
title: "Evaluation of Income annuities with money-back guarantees"
author: "Long Life Insurance Company's Actuarial Team"
output:
word_document:
toc: yes
pdf_document:
fig_width: 6
fig_height: 3.5
fig_caption: yes
fig_crop: no
toc: yes
number_sections: yes
---
[Text]
{r, echo=FALSE, include=TRUE, messages=FALSE, warnings=FALSE, fig.cap = "EPVs at different ages and interest rates"}
plot(xAges,EPVs[1,],ylim=c(min(EPVs),max(EPVs)),main="EPV of CRIA",xlab=
"Annuitant's age",ylab="EPV",pch=1,cex=0.5,col=2)
legend(60,30, legend=c("r = 2%", "r = 4%","r = 6%", "r = 8%"),col=2:5, pch=c(1,3,8,16), cex=1)
[Text]
{r, echo=FALSE, messages=FALSE, warnings=FALSE,fig.cap = "EPVs at different given interest rates"}
plot(IntRates65,EPVs[1,],ylim=c(min(EPVs),max(EPVs)),main="EPV of all 3 products",xlab=
"Interest rate",ylab="EPV",pch=1,cex=0.8,col=2)
legend(0.08, 16, legend=c("LOIA", "IRIA","CRIA"),col=2:4, pch=c(1,3,8), cex=0.8)
[Text]
Tried code above but it sends all plots to the bottom
I think that simply putting each figure in its own chunk with ``` in the beginning and end, will do the trick, like so
---
title: "Evaluation of Income annuities with money-back guarantees"
author: "Long Life Insurance Company's Actuarial Team"
output:
word_document:
toc: yes
pdf_document:
fig_width: 6
fig_height: 3.5
fig_caption: yes
fig_crop: no
toc: yes
number_sections: yes
---
[Text]
```{r, echo=FALSE, include=TRUE, messages=FALSE, warnings=FALSE, fig.cap = "EPVs at different ages and interest rates"}
barplot(c(2,5))
```
[Text]
```{r, echo=FALSE, messages=FALSE, warnings=FALSE,fig.cap = "EPVs at different given interest rates"}
barplot(c(2,5), main="Main title",
xlab="X axis title",
ylab="Y axis title",
sub="Sub-title")
```
[Text]
So I decided to convert my html R markdown file to a pdf knitr and I noticed that half my code output won't show. I replicated a small example here:
---
title: "Test"
author: "Brandon Morgan"
date: "1/19/2021"
output:
pdf_document:
df_print: paged
fig_caption: yes
fig_height: 6
fig_width: 7
highlight: tango
toc: yes
toc_depth: 4
html_document:
code_folding: hide
csl: biomed-central.csl
fig_caption: yes
fig_height: 6
number_sections: yes
theme: sandstone
toc: yes
toc_float: yes
---
# TEST
## Data
```{r}
data = iris
head(data)
```
Here's my html knitr output:
Here's my pdf knitr output:
Notice how head(data) does not show for pdf output
quick fix: remove df_print: paged. I can't tell you why it would not produce the result you want at the moment.
---
title: "Test"
author: "Brandon Morgan"
date: "1/19/2021"
output:
pdf_document:
fig_caption: yes
fig_height: 6
fig_width: 7
toc: yes
toc_depth: 4
html_document:
code_folding: hide
csl: biomed-central.csl
fig_caption: yes
fig_height: 6
number_sections: yes
theme: sandstone
toc: yes
toc_float: yes
---
# TEST
## Data
```{r echo=FALSE, results=TRUE}
data = iris
head(data)
```
Is there a possibility to create an internal link to a table in a rmarkdown-article?
I would like to click on this link and then I automatically come to my table.
I want to set the internal link in the text in the Empirical Results-part for table_1.
I've already tried [#table_1] but it doesn't work.
can someone help me?
Here is my example code:
---
title: "title"
subtitle: "subtitle"
author: "me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
keywords: "keywords"
output:
pdf_document:
fig_cap: yes
keep_tex: yes
documentclass: article
capsize: normalsize
fontsize: 11pt
geometry: margin=1in
spacing: doublespacing
footerdate: yes
abstract: 'Insert abstract here'
---
\newcommand*{\keywords}[1]{\textbf{\textit{Keywords---}} #1}
\keywords{keywords}
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
##required packages
library(tidyverse)
library(knitr)
library(kableExtra)
```
# Introduction
# Literature review
# Data and Methodology
# Empirical Results
In table_1 you can see something....
[#table_1]
# Conclusions
\newpage
# References
\newpage
# Appendix
```{r echo=F, warning=F, message=F}
df1 <- tibble(column1= 1:10, column2=11:20)
table_1 <-df1%>%kable("latex",
booktabs=T,
caption = "example table")%>%
kable_styling(latex_options = "hold_position")
table_1
```
I am working in a book, using R and the Tufte library.
I am using the following YAML for each .Rmd Chapter:
---
title: "Chapter 2: A First Linear Program"
header-includes:
\usepackage{longtable}
\usepackage{caption}
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
And the following one is the YAML for the index .Rmd file:
---
title: "Operations Research Using R<br />"
author: "Timothy R. Anderson"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: ["Master4Bookdowns.bib"]
---
# Preface {-}
I have tried different options like adding the sansfont and mainfont in YAML:
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
sansfont: Calibri Light
mainfont: Calibri Light
But it didn't change the font inside the chunk, only the text outside.
Here a simpler example document showing my attempt to change monofont as suggested in the comments:
---
title: "Chapter 2: A First Linear Program"
header-includes:
\usepackage{longtable}
\usepackage{caption}
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
monofont: Times New Roman
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).
```{r base_case_no_pipes_step_4}
model0d <- c("example", 6 + 2 <= 2000)
#fabrication
model0e <- c("example", 8 + 6 <= 2000)
#assembly
```
You have to bring the YAML headers to the right level:
monofont et al. are top-level headers
highlight is below the output format, not below output
The following example uses "Times New Roman" for the code block and XeLaTeX's default font (Latin Modern) for the main text. You can change that with mainfont. In addition, there is no syntax highlighting:
---
title: "Chapter 2: A First Linear Program"
header-includes:
- \usepackage{longtable}
- \usepackage{caption}
monofont: Times New Roman
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
---
\pagestyle{headings}
```{r setup, include=FALSE}
library(tufte)
library(tint)
library(knitr)
library(gridExtra)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(tidy = F)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(width = 30)
```
This is an example, where we can see that text in the book is affected by the use of command
monofont: Times New Roman in the YAML. However, we can see that next chunk, the oucome when generating the tuffte_handout pdf is using a different font and also using multiple colors (no only black as in the main body).
```{r base_case_no_pipes_step_4}
model0d <- c("example", 6 + 2 <= 2000)
#fabrication
model0e <- c("example", 8 + 6 <= 2000)
#assembly
```
Result:
I want to breakdown the authors' names into two lines in Rmarkdown beamer presentation. My YAML is as follows:
---
title: "***"
author:
- Author One
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 14pt
output:
beamer_presentation:
fig_height: 5
fig_width: 8
highlight: tango
theme: metropolis
incremental: true
---
But still, the authors' names printed on the same line. How can I break into two?
If you use the TeX command \newline after the first author this will render on a second line.
---
title: "***"
author:
- Author One\newline
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 14pt
output:
beamer_presentation:
fig_height: 5
fig_width: 8
highlight: tango
theme: metropolis
incremental: true
---