Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Latest commit

 

History

History
100 lines (74 loc) · 3.69 KB

CS_07.md

File metadata and controls

100 lines (74 loc) · 3.69 KB
title week type subtitle reading tasks
Getting Help!
7
Case Study
Learning more about finding help
How to [write a reproducible example](http://adv-r.had.co.nz/Reproducibility.html)
Using [Reprex package](https://reprex.tidyverse.org/)
Learn how to read R help files effectively
Learn how to search for help
Learn how to create a Minimum Working Example (MWE)
Debug existing code
Save your reprex to your course repository as an html file using Export -> "Save As Webpage" in the RStudio "Viewer" Tab.
View Presentation [Open presentation in a new tab](){target='_blank'}
<iframe class='embed-responsive-item' src='' allowfullscreen></iframe> _Click on presentation and then use the space bar to advance to the next slide or escape key to show an overview._

Reading

Tasks

  • Learn how to read R help files effectively
  • Learn how to search for help
  • Learn how to create a Minimum Working Example (MWE)
  • Debug existing code
  • Save your reprex to your course repository as an html file using Export -> "Save As Webpage" in the RStudio "Viewer" Tab.

Libraries

library(tidyverse)
library(reprex)
library(sf)

library(spData)
data(world)

Your problem

You want to make a figure illustrating the distribution of GDP per capita for all countries within each continent using the world data in the spData package.

Your goal

Your desired figure looks something like the following:

Current Version of your code

You have started working on the figure but can't seem to make it work like you want. Here is your current version of the code (and the resulting figure):

ggplot(world,aes(x=gdpPercap, y=continent, color=continent))+
   geom_density(alpha=0.5,color=F)

The second figure is quite different from the one you want. You want to ask for help and so you know that you need to make a reproducible example. Starting with the code above, make the required edits so you can use reprex() to generate a nicely formatted example that you could email or post to a forum to ask for help. See the reading for more help. Note: you do not need to recreate the first figure above, only to use reprex() to illustrate your question and problematic code.

Show Hints

Steps

  1. Download the starter R script (if desired){target="_blank"}. Save this directly to your course folder (repository) so you don't lose track of it!
  2. Add code needed to produce the second plot (loading required libraries above and loading the world data)
  3. Copy the code to your clipboard
  4. run reprex() to generate the reproducible example in the "Viewer Pane"
  5. Export the preview as an html file and save it in your course repository. It should look something like this (note the image is intentionally blurred):
Extra time? Try this...
Fix the code above to recreate the first figure.