๐ป Week 08 - Class Roadmap (90 min)
2022/23 Lent Term
๐ Learning Objectives
This week, we will explore more of the power of markdown and R. We will learn of a recent development in the world of R, called Quarto, which allows us to create documents that are both reproducible and interactive. We will also learn how to use Zotero to manage our references.
โ๏ธ Setup
You need the following installed:
๐ฃ๏ธ Roadmap
Step 1: Collecting and saving academic references
Zotero is a free, open-source reference management software that allows you to collect, organize, cite, and share your research sources. It lives as an extension in your browser and allows you to save references from online databases, websites, and books. It also has a desktop application that allows you to organize your references into collections and create bibliographies.
๐ฏ ACTION ITEM:
- Create a Zotero account
- Install the Zotero extension in your browser.
- Save a few relevant references to your account. (Check out the ๐ Syllabus for some suggestions)
- Export your references as a
.bib
file and save it in yourDS101L
folder.
Step 2: Get set up with RStudio and Quarto
๐ฏ ACTION POINTS:
- Install Quarto.
- Open RStudio and create a new project.
- Download
DS101L_2022_23_W08_lab.qmd
in RStudio
You will see a โchunkโ of R code that loads all the libraries you need to finish the task. It also creates a function avg_gdppercap
. Donโt worry, you wonโt need to understand what is going on โunder the hoodโ โ all you need to know is that if you type in a year
, it returns the average global GDP per capita in that year. There is also a subset of the data for the Chinese population, chinese_pop
.
You will see that there is a series of short headings and sentences without any formatting. We are going to turn this into an appropriately formatted document with three sections.
There are many ways in which you can format your documents in Quarto, please refer to this page as a user guide throughout.
Step 3: Formatting your document - Section 1 (30 min)
Letโs start by formatting the first section of the document, Section 1: Understanding tidy data.
๐ฏ ACTION POINTS:
Turn the line โUnderstanding tidy dataโ into a section header.
Open Zotero and create a new bibliography
Add Wickhamโs article to this bibliography
- https://www.jstatsoft.org/article/view/v059i10
- Include the name of the author, title, journal, number, issue, page range, and DOI
Right-click on the bibliography and select โExport Collectionโ. Create a BibLaTeX document and save it in the same directory as the Quarto document called
references.bib
.Add the following to the YAML header:
bibliography: references.bib
Click on
references.bib
to see the reference Zotero created for the Wickham article.Directly reference the article using
@ArticleReference
.Turn the principles of tidy data into bullet points.
Step 4: Formatting your document - Section 2 (30 min)
Now, letโs format the second section of the document, Section 2: Global trends in GDP per capita.
๐ฏ ACTION POINTS:
- Turn the line โGlobal trends in GDP per capitaโ into a section header.
- Remember the function
avg_gdppercap
? Well, we can use this function (and any R function for that matter) when writing up our results. - Check out the following documentation:
- https://rmarkdown.rstudio.com/lesson-4.html
- Now use inline R code to replace the ellipses (โฆ) with the dollar amounts using the
avg_gdppercap
function.
Step 5: Formatting your document - Section 3 (15 min)
Finally, letโs format the third section of the document, Section 3: Population growth in China.
๐ฏ ACTION POINTS:
- Turn the line โPopulation growth in Chinaโ into a section header.
- As per the previous section, use
chinese_pop
to replace the ellipses (โฆ) with the population figures. - Create a new R code chunk.
- Check out the
knitr::kable
function by typing?kable
into the console on RStudio. This will open documentation for the function, including all the different parameters that can be used. - Use
chinese_pop
as the first argument inkable
. Technically, this is all you need for it to run, but the table looks a bit basic.- Change the variable names year and pop to something more professional looking.
- Left align the entries.