-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Week one #25
Open
AbzAxness
wants to merge
1
commit into
Env-Data-Sci-FA23:main
Choose a base branch
from
AbzAxness:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Week one #25
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
title: "Pull Request Exercise with Kenya Climate Data" | ||
output: html_document | ||
date: "`r Sys.Date()`" | ||
--- | ||
|
||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
``` | ||
|
||
## Assignment Instructions: | ||
|
||
#### Follow VERY carefully and in order! | ||
|
||
1. If you haven't yet, **fork** the Week-1-Intro repo from our class GitHub organization (ENV-Data-Sci-FA23). | ||
|
||
2. Make sure your local repository has all the files/changes your instructors added. To do so go to **your** forked Week-1-Intro repo, in the bar along the top click the 'Sync' dropdown and if the button says 'Update Branch', click it. | ||
|
||
3. **SAVE** this file (in the same folder this one is located) with **YOUR** name instead of 'YOURNAME' in the file name. | ||
|
||
4. Complete the sequence of coding tasks below (to the best of your ability). | ||
|
||
5. Save, Add, Commit, and Push your changes to this file. | ||
|
||
6. Go to **your** forked Week-1-Intro Repo, click the 'Contribute' drop down at the top and click the 'Open Pull Request' button (if this is grayed out that means you have not pushed any changes to GitHub yet). | ||
|
||
7. Provide a title, short description/notes of your changes, and most importantly under 'Reviewers' on the right, type in the username of your **assigned PR reviewer** (which you can find in the 'PR_reviewer_assignments.md' document in this repository. When you are all set, submit the pull request. | ||
|
||
8. **Review your assigned pull request**. You should receive a notification either via GitHub (you can check by clicking the 'notifications' icon directly next to your profile photo in the upper right corner), or you will receive an email link to the email you registered your GitHub account to. | ||
|
||
Follow [these guidelines for reviewing a pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request), give some meaningful feedback, and when you're done 'Approve' the pull request (do NOT close or merge). | ||
|
||
## The coding exercise: | ||
|
||
Work through the steps below to complete this exercise (to the best of your ability) and then save, add, commit and push this file with your coding edits to your forked repo and follow the instructions above for completing the assignment via creating and reviewing a pull request. | ||
|
||
Load in the tidyverse (only package(s) needed for this exercise: | ||
|
||
```{r} | ||
library(tidyverse) | ||
``` | ||
|
||
Read in the 'kenya_county_climates.csv' in the 'data/' folder and assign it to an environmental variable (Hint: use 'read_csv()'). | ||
|
||
```{r} | ||
data <- read_csv("data/kenya_county_climates.csv") | ||
``` | ||
|
||
Write a chain of operations that does the following: | ||
|
||
1. `select()` just the columns that have "Precipitation" in the name (so we are only interested in the precipitation data), AND the 'County' column. | ||
|
||
2. `filter()` all the rows where 'Precipitation_585_90' is **greater than** the mean of all county precipitation values. | ||
|
||
```{r} | ||
data_filtered <- data %>% | ||
select(County, contains("Precipitation")) %>% | ||
filter(Precipitation_585_90 > mean(Precipitation_585_90)) %>% | ||
pivot_longer(cols = -County) | ||
``` | ||
|
||
Question: How many counties have predicted precip values greater than the total average for all counties? | ||
|
||
Using the new dataset created above, create a bar plot of precipitation for each time frame for each county using `facet_wrap()` | ||
|
||
```{r} | ||
data_filtered %>% | ||
ggplot(aes(x = name, y = value)) + | ||
geom_col() + | ||
# fix the labels | ||
theme(axis.text.x = element_text(angle = 90)) + | ||
facet_wrap(~County) | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code for calculating number of counties is not here. The code for plotting a bar graph looks great. |
||
|
||
CHALLENGE: | ||
|
||
This is messy though since we have so many counties. Instead, use `map()` to create an individual bar plot for each County (hint: create a vector of county names from the data, and building off the ggplot code you made above, add in a line to `filter()` out each county (i.e., .x) before creating the plot. AND, no more need to `facet_wrap()` here). | ||
|
||
There are many ways to do this! | ||
|
||
```{r} | ||
counties <- unique(data_filtered$County) | ||
|
||
plots <- | ||
map(counties, | ||
~ data_filtered %>% filter(County == .x) %>% ggplot(aes(x = name, y = value)) + geom_col()) | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work here using pivot_longer to reshape the data from wide format to long format, with each row representing a unique combination of 'County' and a specific type of precipitation.