git clone https://github.com/etc5523-2022/cwdata.git
ETC5523: Communicating with Data
Tutorial 10
🎯 Objectives
- practice writing long-form documentation vignettes
- write functions and its documentation using
usethis
androxygen2
- convert your package documentation into a website with
pkgdown
install.packages(c("pkgdown"))
- Clone the github repo below:
Exercise 9A
Open the cwdata
project directory and create a new vignette via usethis
.
The name of the vignette should be “crops” and the title will be “Our World in Data: Key Crop Yields”.
Your vignette should contain the following:
- A description of the data, including it’s source, and how to access it with your package.
- Two
ggplot2
visualisations with short descriptions, giving examples of things you could learn from thekey_crop_yields
data. If you are stuck on ideas take a look at the charts found on the Our World in Data website. Remember that any external packages you use should be added to your DESCRIPTION file under Suggests.
Once you have finished your vignette, create a README file via usethis
that describes the intent of the package and how you could install it from your github.
Exercise 9B
Build a local pkgdown
website. Modify the pkgdown
YAML file so your website has the following:
- a customised theme for the website
- the vignette is available via “Articles” link in the navbar
Exercise 9C
Now let’s create a function to help us create a “proportional stacked area chart”.
The function will take a vector of numbers and convert them to proportions. Missing values should be removed from the input vector but remain in the output vector.
Here’s some examples of what the output should look like:
Create a new R script in your package called stack-normalise.R
and place the function. Remember to document it and provide examples of use.
Exercise 9D
Inspect the inst
directory. What do you see in there?
How is that code being used in the package?
Write a new shiny app, based on the one in inst
, that converts the current ggplot to a plotly
output. Then, write a new function for the package that will run this app.