cis-ds / reproducible-examples

0 stars 0 forks source link

01-drop-na-example #1

Open bensoltoff opened 2 years ago

bensoltoff commented 2 years ago

Post your reproducible example here.

alabellehahn commented 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)

Siwei-Mao commented 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)

margueritemcg commented 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)

dbuonauro commented 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)
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)

Davidyang0824 commented 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)

julimoth commented 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"
mariiastepanenko commented 2 years ago
## 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)

yinqingzheng commented 2 years ago
## 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)

mschuhler commented 2 years ago
## 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)

FrederickZhengHe commented 2 years ago
## 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"
evaxwu commented 2 years ago
## 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)

youli2154 commented 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)
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)

voejance commented 2 years ago

> # A tibble: 114 × 14

> case year month day location summary fatalities injured total_victims

>

> 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 , male ,

> # age_of_shooter , race , prior_mental_illness

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"



<sup>Created on 2021-11-04 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>
MedhaRaju commented 2 years ago
## 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)

bensoltoff commented 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os Red Hat Enterprise Linux 8.4 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2021-11-04 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.1) #> backports 1.2.1 2020-12-09 [2] CRAN (R 4.0.1) #> cli 3.0.1 2021-07-17 [2] CRAN (R 4.0.1) #> colorspace 2.0-2 2021-06-24 [2] CRAN (R 4.0.1) #> crayon 1.4.1 2021-02-08 [2] CRAN (R 4.0.1) #> DBI 1.1.1 2021-01-15 [2] CRAN (R 4.0.1) #> digest 0.6.27 2020-10-24 [2] CRAN (R 4.0.1) #> dplyr * 1.0.7 2021-06-18 [2] CRAN (R 4.0.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.0.1) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.1) #> fansi 0.5.0 2021-05-25 [2] CRAN (R 4.0.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.1) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.1) #> generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.1) #> ggplot2 * 3.3.5 2021-06-25 [2] CRAN (R 4.0.1) #> glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.0.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.0.1) #> knitr 1.36 2021-09-29 [2] CRAN (R 4.0.1) #> lifecycle 1.0.0 2021-02-15 [2] CRAN (R 4.0.1) #> magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.0.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.1) #> pillar 1.6.2 2021-07-29 [2] CRAN (R 4.0.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.1) #> R6 2.5.0 2020-10-28 [2] CRAN (R 4.0.1) #> rcfss * 0.2.1 2021-08-11 [2] Github (uc-cfss/rcfss@5b60f61) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.0.1) #> rlang 0.4.11 2021-04-30 [2] CRAN (R 4.0.1) #> rmarkdown 2.11 2021-09-14 [2] CRAN (R 4.0.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.1) #> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.1) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.1) #> stringi 1.7.4 2021-08-25 [2] CRAN (R 4.0.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.1) #> styler 1.5.1 2021-07-13 [2] CRAN (R 4.0.1) #> tibble 3.1.3 2021-07-23 [2] CRAN (R 4.0.1) #> tidyselect 1.1.1 2021-04-30 [2] CRAN (R 4.0.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.0.1) #> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.0.1) #> withr 2.4.2 2021-04-18 [2] CRAN (R 4.0.1) #> xfun 0.25 2021-08-06 [2] CRAN (R 4.0.1) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.1) #> #> [1] /home/soltoffbc/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /opt/R/4.0.1/lib/R/library ```
dwx1201 commented 2 years ago
## 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)

gchal15 commented 2 years ago

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

>

> 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 , male ,

> # age_of_shooter , race , prior_mental_illness

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)

tylermandrell commented 2 years ago
## 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os Red Hat Enterprise Linux 8.4 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2021-11-04 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.1) #> backports 1.2.1 2020-12-09 [2] CRAN (R 4.0.1) #> cli 3.0.1 2021-07-17 [2] CRAN (R 4.0.1) #> colorspace 2.0-2 2021-06-24 [2] CRAN (R 4.0.1) #> crayon 1.4.1 2021-02-08 [2] CRAN (R 4.0.1) #> DBI 1.1.1 2021-01-15 [2] CRAN (R 4.0.1) #> digest 0.6.27 2020-10-24 [2] CRAN (R 4.0.1) #> dplyr * 1.0.7 2021-06-18 [2] CRAN (R 4.0.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.0.1) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.1) #> fansi 0.5.0 2021-05-25 [2] CRAN (R 4.0.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.1) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.1) #> generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.1) #> ggplot2 * 3.3.5 2021-06-25 [2] CRAN (R 4.0.1) #> glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.0.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.0.1) #> knitr 1.36 2021-09-29 [2] CRAN (R 4.0.1) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.0.1) #> magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.0.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.1) #> pillar 1.6.2 2021-07-29 [2] CRAN (R 4.0.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.1) #> R6 2.5.0 2020-10-28 [2] CRAN (R 4.0.1) #> rcfss * 0.2.1 2021-10-10 [1] Github (uc-cfss/rcfss@5b60f61) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.0.1) #> rlang 0.4.11 2021-04-30 [2] CRAN (R 4.0.1) #> rmarkdown 2.11 2021-09-14 [2] CRAN (R 4.0.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.1) #> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.1) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.1) #> stringi 1.7.4 2021-08-25 [2] CRAN (R 4.0.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.1) #> styler 1.5.1 2021-07-13 [2] CRAN (R 4.0.1) #> tibble 3.1.3 2021-07-23 [2] CRAN (R 4.0.1) #> tidyselect 1.1.1 2021-04-30 [2] CRAN (R 4.0.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.0.1) #> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.0.1) #> withr 2.4.2 2021-04-18 [2] CRAN (R 4.0.1) #> xfun 0.25 2021-08-06 [2] CRAN (R 4.0.1) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.1) #> #> [1] /home/tmandrell/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /opt/R/4.0.1/lib/R/library ```
Jenny999973 commented 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)

voejance commented 2 years ago
## 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"
  )
MedhaRaju commented 2 years ago
## 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)

jiajuns3 commented 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os Red Hat Enterprise Linux 8.4 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2021-11-04 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.1) #> backports 1.2.1 2020-12-09 [2] CRAN (R 4.0.1) #> cli 3.0.1 2021-07-17 [2] CRAN (R 4.0.1) #> colorspace 2.0-2 2021-06-24 [2] CRAN (R 4.0.1) #> crayon 1.4.1 2021-02-08 [2] CRAN (R 4.0.1) #> DBI 1.1.1 2021-01-15 [2] CRAN (R 4.0.1) #> digest 0.6.27 2020-10-24 [2] CRAN (R 4.0.1) #> dplyr * 1.0.7 2021-06-18 [2] CRAN (R 4.0.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.0.1) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.1) #> fansi 0.5.0 2021-05-25 [2] CRAN (R 4.0.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.1) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.1) #> generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.1) #> ggplot2 * 3.3.5 2021-06-25 [2] CRAN (R 4.0.1) #> glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.0.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.0.1) #> knitr 1.36 2021-09-29 [2] CRAN (R 4.0.1) #> lifecycle 1.0.0 2021-02-15 [2] CRAN (R 4.0.1) #> magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.0.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.1) #> pillar 1.6.2 2021-07-29 [2] CRAN (R 4.0.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.1) #> R6 2.5.0 2020-10-28 [2] CRAN (R 4.0.1) #> rcfss * 0.2.1 2021-08-11 [2] Github (uc-cfss/rcfss@5b60f61) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.0.1) #> rlang 0.4.11 2021-04-30 [2] CRAN (R 4.0.1) #> rmarkdown 2.11 2021-09-14 [2] CRAN (R 4.0.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.1) #> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.1) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.1) #> stringi 1.7.4 2021-08-25 [2] CRAN (R 4.0.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.1) #> styler 1.5.1 2021-07-13 [2] CRAN (R 4.0.1) #> tibble 3.1.3 2021-07-23 [2] CRAN (R 4.0.1) #> tidyselect 1.1.1 2021-04-30 [2] CRAN (R 4.0.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.0.1) #> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.0.1) #> withr 2.4.2 2021-04-18 [2] CRAN (R 4.0.1) #> xfun 0.25 2021-08-06 [2] CRAN (R 4.0.1) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.1) #> #> [1] /home/jiajuns3/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /opt/R/4.0.1/lib/R/library ```
cassiewangggg commented 2 years ago
## 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)

Jenny999973 commented 2 years ago
## 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)

joselyneqv commented 2 years ago
## 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)

bensoltoff commented 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: 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.2.0 (2022-04-22) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.2.0) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.2.0) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.2.0) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.2.0) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.2.0) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.2.0) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.2.0) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.2.0) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.2.0) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.2.0) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.2.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.0) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.2.0) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.2.0) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.2.0) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.2.0) #> highr 0.9 2021-04-16 [2] CRAN (R 4.2.0) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.2.0) #> knitr 1.39 2022-04-26 [1] CRAN (R 4.2.0) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.2.0) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.2.0) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.2.0) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.2.0) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.2.0) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.2.0) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.2.0) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.2.0) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.2.0) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.2.0) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.2.0) #> rcfss * 0.2.4 2022-05-17 [2] Github (uc-cfss/rcfss@1249806) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.2.0) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.2.0) #> rmarkdown 2.14 2022-04-25 [1] CRAN (R 4.2.0) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.2.0) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.2.0) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.2.0) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.2.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.2.0) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.2.0) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.2.0) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.2.0) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.2.0) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.2.0) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.2.0) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.2.0) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.2.0) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.2.0) #> #> [1] /home/soltoffbc/R/x86_64-pc-linux-gnu-library/4.2 #> [2] /opt/R/4.2.0/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
mskim127 commented 2 years ago

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

>

> 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 , male ,

> # age_of_shooter , race , prior_mental_illness

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"

Peter-Yibo-Pan commented 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: 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)

iramkissoon commented 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: 125 × 14

> case year month day location summary fatalities injured total_victims

>

> 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 , male ,

> # age_of_shooter , race , prior_mental_illness

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"

AshleyZR commented 2 years ago
## 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-06-14 [1] Github (uc-cfss/rcfss@ca4464f) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/ziyuren/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
ihomango commented 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: 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"
hi-rachelliu commented 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: 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)

avas1212 commented 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: 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-06-24 [1] Github (uc-cfss/rcfss@ca4464f) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/asinai/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
mskim127 commented 2 years ago
## 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)

runanlin commented 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: 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"
bensoltoff commented 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: 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)

davidicrabtree commented 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: 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-05-17 [2] Github (uc-cfss/rcfss@1249806) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/crabtreed/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
Alakshm1 commented 2 years ago
## 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-05-17 [2] Github (uc-cfss/rcfss@1249806) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/anjanachandran/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
haribala03 commented 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: 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"
micaylaroth9 commented 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: 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-05-17 [2] Github (uc-cfss/rcfss@1249806) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/micaylaroth/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
iramkissoon commented 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: 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)

julianfox102 commented 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: 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)

ulisolovieva commented 2 years ago
## 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [1] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> rcfss * 0.2.4 2022-05-17 [2] Github (uc-cfss/rcfss@1249806) #> reprex 2.0.1 2021-08-05 [2] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xaringanthemer 0.4.1 2021-11-21 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/uliana/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```
BaichenTan commented 2 years ago
## 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)

mskim127 commented 2 years ago
## 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)

Regenchen commented 2 years ago
## 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)

Alakshm1 commented 2 years ago
## 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)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.1 (2021-08-10) #> os Red Hat Enterprise Linux 8.6 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2022-07-05 #> pandoc 2.17.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.1.1) #> backports 1.4.1 2021-12-13 [2] CRAN (R 4.1.1) #> broom 0.8.0 2022-04-13 [2] CRAN (R 4.1.1) #> cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.1.1) #> cli 3.3.0 2022-04-25 [2] CRAN (R 4.1.1) #> colorspace 2.0-3 2022-02-21 [2] CRAN (R 4.1.1) #> crayon 1.5.1 2022-03-26 [2] CRAN (R 4.1.1) #> curl 4.3.2 2021-06-23 [2] CRAN (R 4.1.1) #> DBI 1.1.2 2021-12-20 [2] CRAN (R 4.1.1) #> dbplyr 2.1.1 2021-04-06 [2] CRAN (R 4.1.1) #> digest 0.6.29 2021-12-01 [2] CRAN (R 4.1.1) #> dplyr * 1.0.9 2022-04-28 [2] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1) #> evaluate 0.15 2022-02-18 [2] CRAN (R 4.1.1) #> fansi 1.0.3 2022-03-24 [2] CRAN (R 4.1.1) #> farver 2.1.0 2021-02-28 [2] CRAN (R 4.1.1) #> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1) #> forcats * 0.5.1 2021-01-27 [2] CRAN (R 4.1.1) #> fs 1.5.2 2021-12-08 [2] CRAN (R 4.1.1) #> generics 0.1.2 2022-01-31 [2] CRAN (R 4.1.1) #> ggplot2 * 3.3.6 2022-05-03 [2] CRAN (R 4.1.1) #> glue 1.6.2 2022-02-24 [2] CRAN (R 4.1.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.1.1) #> haven 2.5.0 2022-04-15 [2] CRAN (R 4.1.1) #> here * 1.0.1 2020-12-13 [2] CRAN (R 4.1.1) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1) #> hms 1.1.1 2021-09-26 [2] CRAN (R 4.1.1) #> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1) #> httr 1.4.3 2022-05-04 [2] CRAN (R 4.1.1) #> jsonlite 1.8.0 2022-02-22 [2] CRAN (R 4.1.1) #> knitr 1.39 2022-04-26 [2] CRAN (R 4.1.1) #> labeling 0.4.2 2020-10-20 [2] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.1.1) #> lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.1) #> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.1.1) #> mime 0.12 2021-09-28 [2] CRAN (R 4.1.1) #> modelr 0.1.8 2020-05-19 [2] CRAN (R 4.1.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.1.1) #> pillar 1.7.0 2022-02-01 [2] CRAN (R 4.1.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1) #> purrr * 0.3.4 2020-04-17 [2] CRAN (R 4.1.1) #> R.cache 0.15.0 2021-04-30 [2] CRAN (R 4.1.1) #> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1) #> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1) #> R.utils 2.11.0 2021-09-26 [2] CRAN (R 4.1.1) #> R6 2.5.1 2021-08-19 [2] CRAN (R 4.1.1) #> readr * 2.1.2 2022-01-30 [2] CRAN (R 4.1.1) #> readxl 1.4.0 2022-03-28 [2] CRAN (R 4.1.1) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1) #> rlang 1.0.2 2022-03-04 [2] CRAN (R 4.1.1) #> rmarkdown 2.14 2022-04-25 [2] CRAN (R 4.1.1) #> rprojroot 2.0.3 2022-04-02 [2] CRAN (R 4.1.1) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1) #> rvest 1.0.2 2021-10-16 [2] CRAN (R 4.1.1) #> scales 1.2.0 2022-04-13 [2] CRAN (R 4.1.1) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.1.1) #> stringi 1.7.6 2021-11-29 [2] CRAN (R 4.1.1) #> stringr * 1.4.0 2019-02-10 [2] CRAN (R 4.1.1) #> styler 1.7.0 2022-03-13 [2] CRAN (R 4.1.1) #> tibble * 3.1.7 2022-05-03 [2] CRAN (R 4.1.1) #> tidyr * 1.2.0 2022-02-01 [2] CRAN (R 4.1.1) #> tidyselect 1.1.2 2022-02-21 [2] CRAN (R 4.1.1) #> tidyverse * 1.3.1 2021-04-15 [2] CRAN (R 4.1.1) #> tzdb 0.3.0 2022-03-28 [2] CRAN (R 4.1.1) #> utf8 1.2.2 2021-07-24 [2] CRAN (R 4.1.1) #> vctrs 0.4.1 2022-04-13 [2] CRAN (R 4.1.1) #> withr 2.5.0 2022-03-03 [2] CRAN (R 4.1.1) #> xfun 0.31 2022-05-10 [2] CRAN (R 4.1.1) #> xml2 1.3.3 2021-11-30 [2] CRAN (R 4.1.1) #> yaml 2.3.5 2022-02-21 [2] CRAN (R 4.1.1) #> #> [1] /home/anjanachandran/R/x86_64-pc-linux-gnu-library/4.1 #> [2] /opt/R/4.1.1/lib/R/library #> #> ────────────────────────────────────────────────────────────────────────────── ```