Open bensoltoff opened 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 × 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-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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)
librar9(reprex)
#> Error in librar9(reprex): could not find function "librar9"
# 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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): 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/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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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)
library(reprex)
# 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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): 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/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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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)
library(reprex)
# 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
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" )
<sup>Created on 2021-11-04 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>
## 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): could not find function "drop_na"
library(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-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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")
#> Skipping install of 'rcfss' from a github remote, the SHA1 (5b60f614) has not changed since last install.
#> Use `force = TRUE` to force installation
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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
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" )
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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)
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
# 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"
)
## 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/2
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"
)
library(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-11-04 by the reprex package (v2.0.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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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): could not find function "drop_na"
Created on 2021-11-04 by the reprex package (v2.0.1)
## Use the script below to generate a reproducible example
## using the reprex package. Use datapasta::dpasta() to create
## `urban` in the script rather than relying on the source
## CSV file. Once you generate it, post it on
## https://github.com/uc-cfss/reproducible-examples-and-git/issues/1
library(tidyverse)
library(here)
#> here() starts at /tmp/Rtmpk849kB/reprex-2a904e2be8f4d6-flat-ram
# import data file
urban <- read_csv(here("data", "urbanization-state.csv"))
#> Error: '/tmp/Rtmpk849kB/reprex-2a904e2be8f4d6-flat-ram/data/urbanization-state.csv' does not exist.
dpasta(input = urban)
#> Error in dpasta(input = urban): could not find function "dpasta"
tibble::tribble(
~state, ~urbanindex,
"Alabama", 9.605935,
"Alaska", 8.735964,
"American Samoa", 11.08593,
"Arizona", 11.29971,
"Arkansas", 9.259444,
"California", 12.19028,
"Colorado", 11.15445,
"Connecticut", 11.40968,
"Delaware", 11.00999,
"District of Columbia", 13.44057,
"Florida", 11.46484,
"Georgia", 10.55233,
"Guam", 11.08593,
"Hawaii", 11.08621,
"Idaho", 9.593634,
"Illinois", 11.62372,
"Indiana", 10.4105,
"Iowa", 9.593525,
"Kansas", 10.12044,
"Kentucky", 9.789536,
"Louisiana", 10.17518,
"Maine", 9.037091,
"Maryland", 11.71105,
"Massachusetts", 11.83973,
"Michigan", 10.80559,
"Minnesota", 10.45684,
"Mississippi", 8.910859,
"Missouri", 10.20212,
"Montana", 8.470226,
"Nebraska", 10.19912,
"Nevada", 11.76972,
"New Hampshire", 9.917139,
"New Jersey", 12.23565,
"New Mexico", 9.896993,
"New York", 12.55857,
"North Carolina", 10.32481,
"North Dakota", 9.054678,
"Northern Marianas", 11.08593,
"Ohio", 10.87687,
"Oklahoma", 9.93928,
"Oregon", 10.71233,
"Pennsylvania", 11.14623,
"Puerto Rico", 11.57168,
"Rhode Island", 11.72124,
"South Carolina", 10.11142,
"South Dakota", 8.728642,
"Tennessee", 10.19729,
"Texas", 11.17488,
"Utah", 10.96281,
"Vermont", 8.843222,
"Virgin Islands", 11.08593,
"Virginia", 10.90625,
"Washington", 11.11933,
"West Virginia", 9.111112,
"Wisconsin", 10.19131,
"Wyoming", 8.256294
)
#> # A tibble: 56 × 2
#> state urbanindex
#> <chr> <dbl>
#> 1 Alabama 9.61
#> 2 Alaska 8.74
#> 3 American Samoa 11.1
#> 4 Arizona 11.3
#> 5 Arkansas 9.26
#> 6 California 12.2
#> 7 Colorado 11.2
#> 8 Connecticut 11.4
#> 9 Delaware 11.0
#> 10 District of Columbia 13.4
#> # … with 46 more rows
# how do I reorder the bars from largest to smallest?
ggplot(data = urban, mapping = aes(x = state, y = urbanindex)) +
geom_col() +
coord_flip()
#> Error in ggplot(data = urban, mapping = aes(x = state, y = urbanindex)): object 'urban' not found
Created on 2021-11-04 by the reprex package (v2.0.1)
## 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): could not find function "drop_na"
Created on 2021-11-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
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/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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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"
sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur/Monterey 10.16
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] rcfss_0.2.4 ggplot2_3.3.6 dplyr_1.0.9
#>
#> loaded via a namespace (and not attached):
#> [1] pillar_1.7.0 compiler_4.2.0 highr_0.9
#> [4] tools_4.2.0 digest_0.6.29 evaluate_0.15
#> [7] lifecycle_1.0.1 tibble_3.1.7 gtable_0.3.0
#> [10] pkgconfig_2.0.3 rlang_1.0.2 reprex_2.0.1
#> [13] cli_3.3.0 DBI_1.1.2 rstudioapi_0.13
#> [16] yaml_2.3.5 xfun_0.31 fastmap_1.1.0
#> [19] xaringanthemer_0.4.1 withr_2.5.0 stringr_1.4.0
#> [22] knitr_1.39 generics_0.1.2 fs_1.5.2
#> [25] vctrs_0.4.1 grid_4.2.0 tidyselect_1.1.2
#> [28] glue_1.6.2 R6_2.5.1 fansi_1.0.3
#> [31] rmarkdown_2.14 purrr_0.3.4 magrittr_2.0.3
#> [34] scales_1.2.0 ellipsis_0.3.2 htmltools_0.5.2
#> [37] assertthat_0.2.1 colorspace_2.0-3 utf8_1.2.2
#> [40] stringi_1.7.6 munsell_0.5.0 crayon_1.5.1
Created on 2022-07-05 by the reprex package (v2.0.1)
## 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/2
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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## 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: 125 × 14
#> case year month day location summary fatalities injured total_victims
#> <chr> <dbl> <chr> <int> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 Oxford H… 2021 Nov 30 Oxford,… "Ethan… 4 7 11
#> 2 San Jose… 2021 May 26 San Jos… "Samue… 9 0 9
#> 3 FedEx wa… 2021 Apr 15 Indiana… "Brand… 8 7 15
#> 4 Orange o… 2021 Mar 31 Orange,… "Amina… 4 1 5
#> 5 Boulder … 2021 Mar 22 Boulder… "Ahmad… 10 0 10
#> 6 Atlanta … 2021 Mar 16 Atlanta… "Rober… 8 1 9
#> 7 Springfi… 2020 Mar 16 Springf… "Joaqu… 4 0 4
#> 8 Molson C… 2020 Feb 26 Milwauk… "Antho… 5 0 5
#> 9 Jersey C… 2019 Dec 10 Jersey … "David… 4 3 7
#> 10 Pensacol… 2019 Dec 6 Pensaco… "Ahmed… 3 8 11
#> # … with 115 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 2022-07-05 by the reprex package (v2.0.1)
## Use the script below to generate a reproducible example
## using the reprex package. Use datapasta::dpasta() to create
## `urban` in the script rather than relying on the source
## CSV file. Once you generate it, post it on
## https://github.com/uc-cfss/reproducible-examples-and-git/issues/1
library(tidyverse)
library(here)
#> here() starts at /tmp/RtmpJVNLQX/reprex-2145674da291b0-brave-mara
# import data file
urban <- tibble::tribble(
~state, ~urbanindex,
"Alabama", 9.605935,
"Alaska", 8.735964,
"American Samoa", 11.08593,
"Arizona", 11.29971,
"Arkansas", 9.259444
)
# 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 2022-07-05 by the reprex package (v2.0.1)
Post your reproducible example here.