Closed bensoltoff closed 2 years ago
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v1.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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.
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt~ 2019 Aug 4 Dayton,~ "PENDI~ 9 27 36
#> 2 El P~ 2019 Aug 3 El Paso~ "PENDI~ 20 26 46
#> 3 Gilr~ 2019 Jul 28 Gilroy,~ "Santi~ 3 12 15
#> 4 Virg~ 2019 May 31 Virgini~ "DeWay~ 12 4 16
#> 5 Harr~ 2019 Feb 15 Aurora,~ "Gary ~ 5 6 11
#> 6 Penn~ 2019 Jan 24 State C~ "Jorda~ 3 1 4
#> 7 SunT~ 2019 Jan 23 Sebring~ "Zephe~ 5 0 5
#> 8 Merc~ 2018 Nov 19 Chicago~ "Juan ~ 3 0 3
#> 9 Thou~ 2018 Nov 7 Thousan~ "Ian D~ 12 22 34
#> 10 Tree~ 2018 Oct 27 Pittsbu~ "Rober~ 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>
#> # A tibble: 114 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v1.0.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# devtools::install_github("uc-cfss/rcfss")
library(rcfss)
# load the data
data("mass_shootings")
# using reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt~ 2019 Aug 4 Dayton,~ "PENDI~ 9 27 36
#> 2 El P~ 2019 Aug 3 El Paso~ "PENDI~ 20 26 46
#> 3 Gilr~ 2019 Jul 28 Gilroy,~ "Santi~ 3 12 15
#> 4 Virg~ 2019 May 31 Virgini~ "DeWay~ 12 4 16
#> 5 Harr~ 2019 Feb 15 Aurora,~ "Gary ~ 5 6 11
#> 6 Penn~ 2019 Jan 24 State C~ "Jorda~ 3 1 4
#> 7 SunT~ 2019 Jan 23 Sebring~ "Zephe~ 5 0 5
#> 8 Merc~ 2018 Nov 19 Chicago~ "Juan ~ 3 0 3
#> 9 Thou~ 2018 Nov 7 Thousan~ "Ian D~ 12 22 34
#> 10 Tree~ 2018 Oct 27 Pittsbu~ "Rober~ 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
library(dplyr)
library(ggplot2)
library(rcfss)
data("mass_shootings") mass_shootings
mass_shootings %>% count(race) %>% drop_na(race) %>% ggplot(mapping = aes(x = reorder(race, -n), y = n)) + geom_col() + labs( title = "Mass shootings in the United States (1982-2019)", x = "Race of perpetrator", y = "Number of incidents" )
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# devtools::install_github("uc-cfss/rcfss")
library(rcfss)
# load the data
data("mass_shootings")
# 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v1.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v0.3.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Dayt… 2019 Aug 4 Dayton,… "PENDI… 9 27 36
#> 2 El P… 2019 Aug 3 El Paso… "PENDI… 20 26 46
#> 3 Gilr… 2019 Jul 28 Gilroy,… "Santi… 3 12 15
#> 4 Virg… 2019 May 31 Virgini… "DeWay… 12 4 16
#> 5 Harr… 2019 Feb 15 Aurora,… "Gary … 5 6 11
#> 6 Penn… 2019 Jan 24 State C… "Jorda… 3 1 4
#> 7 SunT… 2019 Jan 23 Sebring… "Zephe… 5 0 5
#> 8 Merc… 2018 Nov 19 Chicago… "Juan … 3 0 3
#> 9 Thou… 2018 Nov 7 Thousan… "Ian D… 12 22 34
#> 10 Tree… 2018 Oct 27 Pittsbu… "Rober… 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-02-18 by the reprex package (v1.0.0)
## Use the script below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/182
##
## Hint: look at the input and outfile arguments to reprex()
library(tidyverse)
library(here)
#> here() starts at /Users/sterlingfearing/Desktop/uc-cfss-reproducible-examples-and-git-47116e5
# import data file
urban <- read_csv(here("data", "urbanization-state.csv"))
#>
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#> state = col_character(),
#> urbanindex = col_double()
#> )
# how do I reorder the bars from largest to smallest?
ggplot(data = urban, mapping = aes(x = state, y = urbanindex)) +
geom_col() +
coord_flip()
Created on 2021-02-18 by the reprex package (v1.0.0)
library(dplyr)
library(ggplot2)
library(rcfss)
data("mass_shootings") mass_shootings
mass_shootings %>% count(race) %>% drop_na(race) %>% ggplot(mapping = aes(x = reorder(race, -n), y = n)) + geom_col() + labs( title = "Mass shootings in the United States (1982-2019)", x = "Race of perpetrator", y = "Number of incidents" )
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
library(dplyr) library(ggplot2)
library(rcfss)
data("mass_shootings") mass_shootings
mass_shootings %>% count(race) %>% drop_na(race) %>% ggplot(mapping = aes(x = reorder(race, -n), y = n)) + geom_col() + labs( title = "Mass shootings in the United States (1982-2019)", x = "Race of perpetrator", y = "Number of incidents" )
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
reprex::reprex()
#> ℹ Non-interactive session, setting `html_preview = FALSE`.
#> CLIPR_ALLOW has not been set, so clipr will not run interactively
#> Error in switch(where, expr = stringify_expression(x_expr), clipboard = ingest_clipboard(), : EXPR must be a length 1 vector
Created on 2021-07-13 by the reprex package (v2.0.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/181
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 x 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-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/181
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 x 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() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/Discussion/issues/180
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 x 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): could not find function "drop_na"
Created on 2021-07-13 by the reprex package (v2.0.0)
## Copy the code below to generate a reproducible example
## using the reprex package. Once you generate it, post it on
## https://github.com/uc-cfss/reproducible-examples-and-git/issues/1
library(dplyr)
#>
#> Attaching package:'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
# 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 reorder() and aggregating the data before plotting
mass_shootings %>%
count(race) %>%
drop_na(race) %>%
ggplot(mapping = aes(x = reorder(race, -n), y = n)) +
geom_col() +
labs(
title = "Mass shootings in the United States (1982-2019)",
x = "Race of perpetrator",
y = "Number of incidents"
)
#> Error in drop_na(., race): 没有"drop_na"这个函数
Created on 2021-11-04 by the reprex package (v2.0.1)
Post your reproducible example here