Editing Statistics and Statistical Programming (Winter 2021)/Problem set 7
From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 47: | Line 47: | ||
# A plot of the proportion all searches accounted for within each <code>subject_race</code> category each month. | # A plot of the proportion all searches accounted for within each <code>subject_race</code> category each month. | ||
Here's a suggestion for how you might approach this: | |||
Here's | |||
1. Create a new data frame that aggregates stop and search data across sub-groups of <code>subject_race</code> per month. This object could include the following columns: | 1. Create a new data frame that aggregates stop and search data across sub-groups of <code>subject_race</code> per month. This object could include the following columns: | ||
* date as a month/year (should be a date or date-time object | * date as a month/year (should be a date or date-time object) | ||
* race/ethnicity (from the <code>subject_race</code> variable) | * race/ethnicity (from the <code>subject_race</code> variable) | ||
* number of stops (within the <code>subject_race</code> group identified for the row) | * number of stops (within the <code>subject_race</code> group identified for the row) | ||
Line 58: | Line 56: | ||
* total number of searches that month/year | * total number of searches that month/year | ||
* proportion of total searches (within the <code>subject_race</code> group identified for the row). | * proportion of total searches (within the <code>subject_race</code> group identified for the row). | ||
''Note that this will result in a data frame with multiple rows per month/year (as many as one row for each <code>subject_race</code> category).'' | ''Note that this will result in a data frame with multiple rows per month/year (as many as one row for each <code>subject_race</code> category).'' | ||
2. Use <code>ggplot2</code> and the [https://ggplot2.tidyverse.org/reference/geom_path.html <code>geom_line</code>] layer to generate each of the plots. Note that you'll want to assign <code>subject_race</code> as an aesthetic element (<code>aes</code>) for some of the plots so that ggplot2 represents each category as a separate line (maybe distinguished by color?). Make sure to incorporate useful titles, axis labels, and legends for each plot you produce. Recall that the R tutorials include examples of using <code>aes</code> with <code>ggplot2</code>. | 2. Use <code>ggplot2</code> and the [https://ggplot2.tidyverse.org/reference/geom_path.html <code>geom_line</code>] layer to generate each of the plots. Note that you'll want to assign <code>subject_race</code> as an aesthetic element (<code>aes</code>) for some of the plots so that ggplot2 represents each category as a separate line (maybe distinguished by color?). Make sure to incorporate useful titles, axis labels, and legends for each plot you produce. Recall that the R tutorials include examples of using <code>aes</code> with <code>ggplot2</code>. |