# This chunk ensures that the thesisdown package is # installed and loaded. This thesisdown package includes # the template files for the thesis and also two functions # used for labeling and referencing if (!require(remotes)) { if (params$`Install needed packages for {thesisdown}`) { install.packages("remotes", repos = "https://cran.rstudio.com") } else { stop( paste( 'You need to run install.packages("remotes")', "first in the Console." ) ) } } if (!require(dplyr)) { if (params$`Install needed packages for {thesisdown}`) { install.packages("dplyr", repos = "https://cran.rstudio.com") } else { stop( paste( 'You need to run install.packages("dplyr")', "first in the Console." ) ) } } if (!require(ggplot2)) { if (params$`Install needed packages for {thesisdown}`) { install.packages("ggplot2", repos = "https://cran.rstudio.com") } else { stop( paste( 'You need to run install.packages("ggplot2")', "first in the Console." ) ) } } if (!require(bookdown)) { if (params$`Install needed packages for {thesisdown}`) { install.packages("bookdown", repos = "https://cran.rstudio.com") } else { stop( paste( 'You need to run install.packages("bookdown")', "first in the Console." ) ) } } if (!require(thesisdown)) { if (params$`Install needed packages for {thesisdown}`) { remotes::install_github("ismayc/thesisdown") } else { stop( paste( "You need to run", 'remotes::install_github("ismayc/thesisdown")', "first in the Console." ) ) } } library(thesisdown) library(dplyr) library(ggplot2) library(knitr) flights <- read.csv("data/flights.csv", stringsAsFactors = FALSE)
If your thesis has a lot of figures, R Markdown might behave better for you than that other word processor. One perk is that it will automatically number the figures accordingly in each chapter. You'll also be able to create a label for each figure, add a caption, and then reference the figure in a way similar to what we saw with tables earlier. If you label your figures, you can move the figures around and R Markdown will automatically adjust the numbering for you. No need for you to remember! So that you don't have to get too far into LaTeX to do this, a couple R functions have been created for you to assist. You'll see their use below.
In the R chunk below, we will load in a picture stored as reed.jpg
in our main directory. We then give it the caption of "Reed logo", the label of "reedlogo", and specify that this is a figure. Make note of the different R chunk options that are given in the R Markdown file (not shown in the knitted document).
include_graphics(path = "figure/reed.jpg")
Here is a reference to the Reed logo: Figure \@ref(fig:reedlogo). Note the use of the fig:
code here. By naming the R chunk that contains the figure, we can then reference that figure later as done in the first sentence here. We can also specify the caption for the figure via the R chunk option fig.cap
.
\clearpage
Below we will investigate how to save the output of an R plot and label it in a way similar to that done above. Recall the flights
dataset from Chapter \@ref(rmd-basics). (Note that we've shown a different way to reference a section or chapter here.) We will next explore a bar graph with the mean flight departure delays by airline from Portland for 2014.
mean_delay_by_carrier <- flights %>% group_by(carrier) %>% summarize(mean_dep_delay = mean(dep_delay)) ggplot(mean_delay_by_carrier, aes(x = carrier, y = mean_dep_delay)) + geom_bar(position = "identity", stat = "identity", fill = "red")
Here is a reference to this image: Figure \@ref(fig:delaysboxplot).
A table linking these carrier codes to airline names is available at https://github.com/ismayc/pnwflights14/blob/master/data/airlines.csv.
\clearpage
Next, we will explore the use of the out.extra
chunk option, which can be used to shrink or expand an image loaded from a file by specifying "scale= "
. Here we use the mathematical graph stored in the "subdivision.pdf" file.
include_graphics("figure/subdivision.pdf")
Here is a reference to this image: Figure \@ref(fig:subd). Note that echo=FALSE
is specified so that the R code is hidden in the document.
More Figure Stuff
Lastly, we will explore how to rotate and enlarge figures using the out.extra
chunk option. (Currently this only works in the PDF version of the book.)
include_graphics("figure/subdivision.pdf")
As another example, here is a reference: Figure \@ref(fig:subd2).
You might want to footnote something. ^[footnote text] The footnote will be in a smaller font and placed appropriately. Endnotes work in much the same way. More information can be found about both on the CUS site or feel free to reach out to data@reed.edu.
Of course you will need to cite things, and you will probably accumulate an armful of sources. There are a variety of tools available for creating a bibliography database (stored with the .bib extension). In addition to BibTeX suggested below, you may want to consider using the free and easy-to-use tool called Zotero. The Reed librarians have created Zotero documentation at https://libguides.reed.edu/citation/zotero. In addition, a tutorial is available from Middlebury College at https://sites.middlebury.edu/zoteromiddlebury/.
R Markdown uses pandoc (https://pandoc.org/) to build its bibliographies. One nice caveat of this is that you won't have to do a second compile to load in references as standard LaTeX requires. To cite references in your thesis (after creating your bibliography database), place the reference name inside square brackets and precede it by the "at" symbol. For example, here's a reference to a book about worrying: [@Molina1994]. This Molina1994
entry appears in a file called thesis.bib
in the bib
folder. This bibliography database file was created by a program called BibTeX. You can call this file something else if you like (look at the YAML header in the main .Rmd file) and, by default, is to placed in the bib
folder.
For more information about BibTeX and bibliographies, see our CUS site (https://web.reed.edu/cis/help/latex/index.html)^[@reedweb2007]. There are three pages on this topic: bibtex (which talks about using BibTeX, at https://web.reed.edu/cis/help/latex/bibtex.html), bibtexstyles (about how to find and use the bibliography style that best suits your needs, at https://web.reed.edu/cis/help/latex/bibtexstyles.html) and bibman (which covers how to make and maintain a bibliography by hand, without BibTeX, at https://web.reed.edu/cis/help/latex/bibman.html). The last page will not be useful unless you have only a few sources.
If you look at the YAML header at the top of the main .Rmd file you can see that we can specify the style of the bibliography by referencing the appropriate csl file. You can download a variety of different style files at https://www.zotero.org/styles. Make sure to download the file into the csl folder.
\vfill
Tips for Bibliographies
Author = {Noble, Sam and Youngberg, Jessica},
.If you'd like to see examples of other things in this template, please contact the Data @ Reed team (email data@reed.edu) with your suggestions. We love to see people using R Markdown for their theses, and are happy to help.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.