Before you start

Exercise 1. Default documents and output styles

a. Generate a default Rmarkdown document with html output b. Change the output options to PDF and Word. i. Question: What changes happen to the YAML? ii. Question: Which output format do you think looks best?

Note: Your computer may not have Latex installed, if so see the solutions for the PDF output

Exercise 2. Lists and formatting

a. Replace the contents of the Rmarkdown document (from ## R Markdown on line 12 onwards) with a numbered list of your 5 New Year's resolutions (you can make these up...?!) i. Give your document a title, change the author and check the date is correct ii. Make bold any/all resolutions you still haven't broken iii. Strikethrough resolutions you have broken and add the date as an indented bullet point (note: 4 blank spaces to indent) iv. 'Knit' the document to your preferred output (check it looks as expected) v. Optional: Explore other text formatting options described on the RMarkdown cheatsheet

Exercise 3. Embedding plots, tables and inline maths

a. Start a new Rmarkdown document, select your preferred output style b. Delete the default text (from line 12) c. Plots: i. Insert a blank chunk or R code ii. Add the code for a plot to this chunk (use plots from previous sessions or start with the mpg dataset in the ggplot2 package) d. Tables: i. Insert another blank chunk of r code, include the option results="asis" in the chunk options - what happens? ii. Add the following code in a chunk to create a table: r library(BristolVis) library(arsenal) table_one <- tableby(diet ~ bmi + sex, data = bmi, test=TRUE, # include tests of associations between diet and exposures total=TRUE, # include a total column control=tableby.control(digits=1)) # to control how many decimal places are in the table summary(table_one)
iii. Optional 1: Compare outputs from the arsenal package with tables generated by the table or ftable commands. iv. Optional 2: Explore other tables which can be generated by the arsenal package

e. Inline R code i. Add a new heading 'Inline R code' after the latest chunk ii. Combine text and inline R code to describe the number of rows in the BristolVis::bmi dataset (nrow(BristolVis::bmi)) iii. Describe the mean BMI (bmi$bmi) and its associated standard deviation. iv. Optional: format the mean and standard deviation to show only 1 decimal place.

Exercise 4. Chunk options

a. Using the previous Rmarkdown document use chunk option echo=TRUE/FALSE to change whether the R code is printed in the output b. Use the chunk option eval=TRUE/FALSE to control whether the code in the chunk is run c. Change the size of the first plot by varying the fig.width or fig.height chunk options d. Add a caption to the boxplot using the fig.cap = "Caption text goes in here" option i. Vary the output formats, does the caption still look right?

Exercise 5. Optional: RNotebook

a. Load a new RNotebook i. File -> New File -> R Notebook b. Click the 'Preview' button i. Does the output include a plot? c. In the RNotebook run the chunk of R code containing the plot by clicking on the green 'play' in the top right corner of the chunk d. Add in code chunks from previous exercises and explore whether chunks have to be run in order or can be run out of order e. Explore toggling the visibility of code in the output document

Solutions

The Rmd files and their corresponding html, pdf, and word outputs can be obtained from the `BristolVis' webpage.



statcourses/BristolVis documentation built on Jan. 31, 2021, 9:24 p.m.