-
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
Coding exercise #10
base: main
Are you sure you want to change the base?
Coding exercise #10
Conversation
1. `select()` just the columns that have "Precipitation" in the name (so we are only interested in the precipitation data), AND the 'County' column. | ||
```{r} | ||
KenyaPre <- Kenya %>% | ||
select(County,contains("Precipitation")) |
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.
This is a very efficient way to select any column with the word "precipitation"! I used matches instead of contains.
Kenyapivot%>% | ||
ggplot() + | ||
geom_col(aes(x=name, y=value)) + | ||
facet_wrap(county) |
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.
This is a good way to create your plot.
Hers is another code string with labels included:
data_filtered %>%
ggplot(aes(x = name, y = value)) +
geom_col() +
theme(axis.text.x = element_text(angle = 90)) +
facet_wrap(~County)
Also, don't forget the "~" in facet_wrap!
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! | ||
|
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.
I also was not able to get to the challenge question, but here is the solution:
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good job Ashlee <3
please review hehe (didn't get far lol)