```{r}
#LOAD PACKAGES
library(tidyverse)
```
Notes N
Pretty Documents: Tables with kableExtra
, Figure Captions, Cross-referencing, and Bibliographies
kableExtra
for pretty tables
By default, Quarto displays data frames and matrices as you’d see them in the console and it’s kind of ugly.
```{r}
%>%
cars head()
```
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
There are many different packages for making tables prettier including kableExtra
, gt
, longtable
, huxtable
, stargazer
and others.
In this class, we are going to focus on kableExtra
since it’s relatively simple and easy to use and it works well in many output formats (.html, .pdf, etc.)
```{r}
library(kableExtra)
```
A basic pretty looking table can be accessing by applying the kbl()
function:
```{r}
%>%
cars head() %>%
kbl()
```
speed | dist |
---|---|
4 | 2 |
4 | 10 |
7 | 4 |
7 | 22 |
8 | 16 |
9 | 10 |
We can customize this even further with the kable_styling()
function:
```{r}
%>%
cars head() %>%
kbl() %>%
kable_styling()
```
speed | dist |
---|---|
4 | 2 |
4 | 10 |
7 | 4 |
7 | 22 |
8 | 16 |
9 | 10 |
There are many different options for kable_styling()
. Below are a few:
```{r}
%>%
cars head() %>%
kbl() %>%
kable_styling(font_size=2)
```
speed | dist |
---|---|
4 | 2 |
4 | 10 |
7 | 4 |
7 | 22 |
8 | 16 |
9 | 10 |
A great guide for many different customizations of tables is available at https://haozhu233.github.io/kableExtra/awesome_table_in_html.html
Bibliography using .bib
files
- Create a
bibliography.bib.bib
file
We begin by creating a.bib-file called bibliography.bib
which is then filled with BibTeX entries. BibTeX entries are built in the following format and contain enough information for citation and bibliography inclusion for each literature source (book, essay, etc.).
@book{Hemingway1952,
title={The Old Man and the Sea},
author={Hemingway, Ernest},
year={1952},
publisher={Charles Scribner's Sons}
}
You can usually download .bib information directly from the source (the journal or article). For example: At https://academic.oup.com/bioscience/article/69/1/40/5195956 click on “Cite”
You can use a .bib citation generator like Bibcitation to create the reference for you
You can use a citation manager (like Zotero, MyBiB, etc.) and download a bibliography.bib file for all your sources at once.
- Add the bibliography to your Quarto document
Add bibliography: bibliography.bib
to your YAML header
---
title: "Blah Blah"
author: "EMW"
bibliography: bibliography.bib
output: html_document
---
- Reference within your document
For example:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent enim urna, dapibus et bibendum vel, consectetur et turpis. Cras a molestie nulla. [@Hemingway1952]
This will create an inline citation to that source AND include that source in a bibliography at the end of your document.
Note that any references that are not referenced within your document (but are in your bibliography) will NOT be displayed in your bibliography by default.
Other general reminders
- make sure that all warnings and messages are hidden. This should be done by default globally if you already have the following in your YAML header (see below). Otherwise, you can add these as chunk options.
execute:
message: FALSE
warning: FALSE
- Run spellcheck on your project (see the little ABC with the green check?)