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

exercise2 #10

Open
mikaylastein opened this issue Nov 4, 2021 · 0 comments
Open

exercise2 #10

mikaylastein opened this issue Nov 4, 2021 · 0 comments

Comments

@mikaylastein
Copy link

library(tidyverse)

# get data from rcfss package
# install latest version if not already installed
# devtools::install_github("uc-cfss/rcfss")
library(rcfss)

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 × 14
#>    case     year month   day location summary   fatalities injured total_victims
#>    <chr>   <dbl> <chr> <int> <chr>    <chr>          <dbl>   <dbl>         <dbl>
#>  1 Dayton…  2019 Aug       4 Dayton,… "PENDING"          9      27            36
#>  2 El Pas…  2019 Aug       3 El Paso… "PENDING"         20      26            46
#>  3 Gilroy…  2019 Jul      28 Gilroy,… "Santino…          3      12            15
#>  4 Virgin…  2019 May      31 Virgini… "DeWayne…         12       4            16
#>  5 Harry …  2019 Feb      15 Aurora,… "Gary Ma…          5       6            11
#>  6 Pennsy…  2019 Jan      24 State C… "Jordan …          3       1             4
#>  7 SunTru…  2019 Jan      23 Sebring… "Zephen …          5       0             5
#>  8 Mercy …  2018 Nov      19 Chicago… "Juan Lo…          3       0             3
#>  9 Thousa…  2018 Nov       7 Thousan… "Ian Dav…         12      22            34
#> 10 Tree o…  2018 Oct      27 Pittsbu… "Robert …         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

# Generate a bar chart that identifies the number of mass shooters
# associated with each race category. The bars should be sorted
# from highest to lowest.

# using forcats::fct_infreq() and using the raw data for plotting
mass_shootings %>%
  drop_na(race) %>%
  ggplot(mapping = aes(x = fct_infreq(race))) +
  geom_bar() +
  coord_flip() +
  labs(
    title = "Mass shootings in the United States (1982-2019)",
    x = "Race of perpetrator",
    y = "Number of incidents"
  )

Created on 2021-11-04 by the reprex package (v2.0.1)

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

No branches or pull requests

1 participant