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

Commit

Permalink
update ps03
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam M. Wilson committed Sep 16, 2020
1 parent d4f4f51 commit edbf6b9
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 258 deletions.
10 changes: 6 additions & 4 deletions CS_03.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library(ggplot2)
library(scales)
gapminder <- gapminder %>% filter(country != "Kuwait")
gapminder.continent <- gapminder %>%
gapminder_continent <- gapminder %>%
group_by(continent, year) %>%
summarise(gdpPercap = weighted.mean(x = gdpPercap, w = pop),
pop = sum(as.numeric(pop)))
Expand All @@ -66,7 +66,8 @@ p1=ggplot(data = gapminder, aes(color = continent, x = lifeExp, y = gdpPercap, s
p2=ggplot(data = gapminder, aes(color = continent, x = year, y = gdpPercap)) +
geom_point(aes(size = pop/100000)) +
geom_line(aes(group = country)) +
geom_point(data = gapminder.continent, color = "black", aes(size = pop/100000)) + geom_line(data = gapminder.continent, color = "black") +
geom_point(data = gapminder_continent, color = "black", aes(size = pop/100000)) +
geom_line(data = gapminder_continent, color = "black") +
facet_wrap(~continent, nrow = 1) +
theme_bw() +
labs(x = "Year", y = "GDP per capita", color = "Continent", size = "Population (100k)")
Expand All @@ -92,13 +93,14 @@ p2
* Use `group_by()` to group by `continent` and `year`
* Use `summarize()` with the below commands to calculate the data for the black continent average line on the second plot:
* `gdpPercapweighted = weighted.mean(x = gdpPercap, w = pop)`
* `pop = sum(as.numeric(pop))`
* `pop = sum(as.numeric(pop))`
* Save this aggregated data as an object called `gapminder_continent`
4. Plot #2 (the second row of plots)
* Use `ggplot()` and the `theme_bw()` to duplicate the second plot. In this plot you will add elements from both the raw gapminder dataset and your dataset summarized by continent. You will need to use the new data you summarized to add the black lines and dots showing the continent average. So it will look something like this:
` ggplot(gapminder,...) + geom_line() + geom_point() + geom_line(data=newdata,...) + ` `geom_point(data=newdata,...) + facet_wrap() + theme_bw() + labs(...)`
5. Use `ggsave()` or `png()` and save each plot as a `.png` with a width of 15 inches
6. Click `Source` to confirm that your script runs from start to finish without errors and saves the graphics.
7. Save your script as an .R or .Rmd in your course repository.
7. Save your script as `case_study_03.R` or `case_study_03.Rmd` (if you are starting to play with R Markdown) in your course repository for week 3.

## Next steps

Expand Down
5 changes: 3 additions & 2 deletions CS_03.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ In this exercise you will recreate the two graphics shown below using `gapminder
* Use `group_by()` to group by `continent` and `year`
* Use `summarize()` with the below commands to calculate the data for the black continent average line on the second plot:
* `gdpPercapweighted = weighted.mean(x = gdpPercap, w = pop)`
* `pop = sum(as.numeric(pop))`
* `pop = sum(as.numeric(pop))`
* Save this aggregated data as an object called `gapminder_continent`
4. Plot #2 (the second row of plots)
* Use `ggplot()` and the `theme_bw()` to duplicate the second plot. In this plot you will add elements from both the raw gapminder dataset and your dataset summarized by continent. You will need to use the new data you summarized to add the black lines and dots showing the continent average. So it will look something like this:
` ggplot(gapminder,...) + geom_line() + geom_point() + geom_line(data=newdata,...) + ` `geom_point(data=newdata,...) + facet_wrap() + theme_bw() + labs(...)`
5. Use `ggsave()` or `png()` and save each plot as a `.png` with a width of 15 inches
6. Click `Source` to confirm that your script runs from start to finish without errors and saves the graphics.
7. Save your script as an .R or .Rmd in your course repository.
7. Save your script as `case_study_03.R` or `case_study_03.Rmd` (if you are starting to play with R Markdown) in your course repository for week 3.

## Next steps

Expand Down
Binary file removed CS_03_files/figure-html/code1-1.png
Binary file not shown.
Binary file removed CS_03_files/figure-html/code1-2.png
Binary file not shown.
2 changes: 1 addition & 1 deletion Schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We will refer to the following texts (all available online):
|:-|:-|:-:|:---:|:---:|:---:|
| 1 | 8/31/20 | [<i class='fas fa-desktop'> </i>](pres/PS_01.html){target='_blank'} | [Getting Started](./TK_01.html) | [Your first script](./CS_01.html) | Introduction to R |
| 2 | 9/7/20 | [<i class='fas fa-desktop'> </i>](pres/PS_02.html){target='_blank'} | [Graphics Background and Getting started with RStudio](./TK_02.html) | [My grandfather says climate is cooling](./CS_02.html) | Introduction to Data Visualization with ggplot |
| 3 | 9/14/20 | [<i class='fas fa-desktop'> </i>](https://docs.google.com/presentation/d/e/2PACX-1vQz-fvEBOO92SUMjbdfmlr3aQ4AYVTrblX1R33DTOxMYJIF5icvGhzOinvf4cdAgqmc2NFA7gFf_Wmx/pub?start=false&loop=false&delayms=3000){target='_blank'} | [Git Repository](./TK_03.html) | [Wealth over time](./CS_03.html) | Introduction to the Tidyverse |
| 3 | 9/14/20 | [<i class='fas fa-desktop'> </i>](pres/PS_03_Git.html){target='_blank'} | [Git Repository](./TK_03.html) | [Wealth over time](./CS_03.html) | Introduction to the Tidyverse |
| 4 | 9/21/20 | [<i class='fas fa-desktop'> </i>](https://docs.google.com/presentation/d/e/2PACX-1vQGwl7rKVV13salaZ9-wTf4hLggWIV4ydTjKlkMSm8LA6oO10tusMBtzaGIaY_vPVD1wf-QO9Y_tqHW/pub?start=false&loop=false&delayms=3000){target='_blank'} | [Data Wrangling 2](./TK_04.html) | [Farthest airport from New York City](./CS_04.html) | Communicating with Data in the Tidyverse |
| 5 | 9/28/20 | [<i class='fas fa-desktop'> </i>](pres/PS_05.html){target='_blank'} | [Spatial Vector Data](./TK_05.html) | [Beware the Canadians!](./CS_05.html) | Visualizing Geospatial Data in R |
| 6 | 10/5/20 | [<i class='fas fa-desktop'> </i>](pres/PS_06_raster.html){target='_blank'} | [Spatial Raster Data](./TK_06.html) | [Find hottest country on each continent](./CS_06.html) | Spatial Analysis in R with sf and raster |
Expand Down
2 changes: 1 addition & 1 deletion TK_04.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tasks:
- Briefly describe functions that seem especially useful in the README.md file for this week.
- Confirm that all tasks and case studies you have completed have been committed in your course repository and pushed to Github.
- Look ahead at Task 6 (Project Proposal) and start thinking about possibilities
- Post at least one rough project idea (with links, etc.) to Slack in the [Project Channel](https://ubspatialdatascience.slack.com/messages/CDNEG4WN8).
- Post at least one rough project idea (with links, etc.) to Slack in the Projects Channel.
---

# Reading
Expand Down
3 changes: 2 additions & 1 deletion docs/CS_03.html
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,15 @@ <h2>Detailed Steps</h2>
<li><code>gdpPercapweighted = weighted.mean(x = gdpPercap, w = pop)</code></li>
<li><code>pop = sum(as.numeric(pop))</code></li>
</ul></li>
<li>Save this aggregated data as an object called <code>gapminder_continent</code></li>
</ul></li>
<li>Plot #2 (the second row of plots)
<ul>
<li>Use <code>ggplot()</code> and the <code>theme_bw()</code> to duplicate the second plot. In this plot you will add elements from both the raw gapminder dataset and your dataset summarized by continent. You will need to use the new data you summarized to add the black lines and dots showing the continent average. So it will look something like this: <code>ggplot(gapminder,...) + geom_line() + geom_point() + geom_line(data=newdata,...) +</code> <code>geom_point(data=newdata,...) + facet_wrap() + theme_bw() + labs(...)</code></li>
</ul></li>
<li>Use <code>ggsave()</code> or <code>png()</code> and save each plot as a <code>.png</code> with a width of 15 inches</li>
<li>Click <code>Source</code> to confirm that your script runs from start to finish without errors and saves the graphics.</li>
<li>Save your script as an .R or .Rmd in your course repository.</li>
<li>Save your script as <code>case_study_03.R</code> or <code>case_study_03.Rmd</code> (if you are starting to play with R Markdown) in your course repository for week 3.</li>
</ol>
</div>
<div id="next-steps" class="section level2">
Expand Down
Loading

0 comments on commit edbf6b9

Please sign in to comment.