Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Coding exercise #10

wants to merge 1 commit into from

Conversation

ashleeph
Copy link

please review hehe (didn't get far lol)

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"))

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)

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!

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())

Copy link

@tessabirt tessabirt left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants