-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCS_07.Rmd
110 lines (87 loc) · 3.76 KB
/
CS_07.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: "Getting Help!"
week: 7
type: Case Study
subtitle: Learning more about finding help
reading:
- How to [write a reproducible example](http://adv-r.had.co.nz/Reproducibility.html)
- Using [Reprex package](https://reprex.tidyverse.org/)
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
- Post your reprex as an ‘issue’ in github
- Post your repex to slack
---
```{r, echo=FALSE, message=FALSE, results='hide', purl=FALSE}
source("functions.R")
source("knitr_header.R")
```
# Reading
```{r reading,results='asis',echo=F,purl=F}
md_bullet(rmarkdown::metadata$reading)
```
# Tasks
```{r tasks,results='asis',echo=F,purl=F}
md_bullet(rmarkdown::metadata$tasks)
```
## Libraries
```{r purl=F, message=F,warning=FALSE}
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:
```{r, echo=F, purl=F, warning=F, fig.width=15, message=F}
library(spData)
library(rgdal)
library(sf)
library(ggplot2)
data(world)
ggplot(world,aes(x=gdpPercap, fill=continent))+
geom_density(alpha=0.5,color=F)+
labs(x="GDP Per Capita",y="Density")+
theme(legend.position = "bottom")
```
### 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):
```{r, warning=F, fig.width=15}
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 post as a github 'issue,' send as an email or post to a forum to ask for help. See the [reading](https://reprex.tidyverse.org/) 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.
<div class="well">
<button data-toggle="collapse" class="btn btn-primary btn-sm round" data-target="#demo1">Show Hints</button>
<div id="demo1" class="collapse">
## Steps
1. Download the [<i class="fa fa-file-code-o fa-1x" aria-hidden="true"></i> starter R script (if desired)](`r output_nocomment`){target="_blank"}. Save this directly to your course folder (repository) so you don't lose track of it!
2. Add code (only 3 lines) needed to produce the second plot (hint: make sure the data are available)
2. Copy the code to your clipboard
3. Post as an 'issue' in github
1. run `reprex(venue="gh")` to generate the reproducible example and put the content on your clipboard
2. go to _your_ repository on github
3. click on the "issues" tab (to the right of the 'code' tab)
4. click the green 'New issue' button
5. paste the reprex in the "leave a comment" box
6. Add an informative title ("Example repex"?)
4. Post to the slack #reprex channel
1. run `reprex(venue="gh")` to generate the reproducible example
2. paste in the [reprex](https://2021spatialda-dba8777.slack.com/archives/C02HHC8GDFG) channel.
It should look something like this:
![](assets/reprex.png)
</div>
</div>
<div class="extraswell">
<button data-toggle="collapse" class="btn btn-link" data-target="#extras">
Extra time? Try this...
</button>
<div id="extras" class="collapse">
Fix the code above to recreate the first figure.
</div>
</div>