Now that you are near the end of your data analysis, you want to make sure that you’ve plugged in the gaps of REF1 REF2 and so on correctly cited the articles and software you wanted to mention.
12.1 Overview
Teaching
Exercises
12.2 Questions
What sort of things can I cite?
How do I manage my .bib file?
How do I change the citation style?
12.3 Objectives
Provide a bibliography at the end of the document
Cite articles and packages during the document
learn how to manage citation styles
12.4 How to cite things
Citing things in a Quarto document is straightforward, you refer to articles you want to cite using [@article-handle]. Here, article-handle matches the article handle in your .bib file.
This .bib file is referred to in the YAML of your document, under the option bibliography: filename.bib:
.bib is a format for storing references from the heyday of LaTeX. It contains plain text with reference information for the article. Here’s an example one:
@Book{ggplot2,
author = {Hadley Wickham},
title = {ggplot2: Elegant Graphics for Data Analysis},
publisher = {Springer-Verlag New York},
year = {2016},
isbn = {978-3-319-24277-4},
url = {http://ggplot2.org},
}
12.4.2 And how do I generate these .bib files?
You can use the citation function in R for R itself, and for specific R packages.
We can get the citation for R with:
citation()
To cite R in publications use:
R Core Team (2024). _R: A Language and Environment for Statistical
Computing_. R Foundation for Statistical Computing, Vienna, Austria.
<https://www.R-project.org/>.
A BibTeX entry for LaTeX users is
@Manual{,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2024},
url = {https://www.R-project.org/},
}
We have invested a lot of time and effort in creating R, please cite it
when using it for data analysis. See also 'citation("pkgname")' for
citing R packages.
And for ggplot2 with
citation("ggplot2")
To cite ggplot2 in publications, please use
H. Wickham. ggplot2: Elegant Graphics for Data Analysis.
Springer-Verlag New York, 2016.
A BibTeX entry for LaTeX users is
@Book{,
author = {Hadley Wickham},
title = {ggplot2: Elegant Graphics for Data Analysis},
publisher = {Springer-Verlag New York},
year = {2016},
isbn = {978-3-319-24277-4},
url = {https://ggplot2.tidyverse.org},
}
For journals or books, you’ll need to get a specific .bib file. Yes, this can be a bit of a pain, but this is where you need to use a reference management software like Zotero, Mendeley, papers, or paperpile. The important thing to to use something. These all allow you to get .bib files of your articles, which you can then placec in your references.bib file.
Your Turn
Using “05-qmd-bib-polish.qmd”
Generate a references.bib file to place your citations
Using the citation() function, generate citations for the packages we have used, “dplyr”, “ggplot2”, “gapminder”, and for the R software, place these in your references.bib file
Reference these in your document
Add a final heading in your file called #bibliography
Render the document
12.5 How to change the bibliography style
OK so now you’ve got your bibliography, but you now need to change it to a specific journal format. Luckily, this is now pretty easy. You can change your citation style from the citation style language
Similar to how you referred to your .bib file with bibliography: ref.bib, you do something similar:
select your bibliography style to be one from your favourite journal at the CSL github repo here: https://github.com/citation-style-language/styles (> 2,600 citations and counting)
place this in your rstudio project
refer to it in the YAML
Render your document and observe your greatness
12.6 How to move the bibliography location
The bibliography is typically placed at the end of the document, so your last heading should be something like # References. However, if you want to move it, place the following piece of text in the reference section. For example.
If your bibliography is being generated using BibLaTeX or natbib…the bibliography will always appear at the end of the document and the #refs div will be ignored.
12.7 How to not print / suppress the bibliography?
The bibliography can be suppressed with the YAML option suppress-bibliography
title: "document"
output: html
bibliography: file.bib
suppress-bibliography: true
Your Turn
Generate a bibliography and an appendix that follows it