cis-ds / Discussion

Public discussion
10 stars 15 forks source link

02-reorder-graph #144

Closed bensoltoff closed 4 years ago

bensoltoff commented 4 years ago

Post your reproducible example here

IanGGG commented 4 years ago
library(tidyverse)

# get data from rcfss package
# install latest version if not already installed
# devtools::install_github("uc-cfss/rcfss")
library(rcfss)
#> Error in library(rcfss): 不存在叫'rcfss'这个名字的程辑包

# load the data
data("mass_shootings")
#> Warning in data("mass_shootings"): data set 'mass_shootings' not found
mass_shootings
#> Error in eval(expr, envir, enclos): 找不到对象'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 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"
  )
#> Error in eval(lhs, parent, parent): 找不到对象'mass_shootings'

Created on 2020-07-09 by the reprex package (v0.3.0)

sabreena-croteau commented 4 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/Discussion/issues/144

library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 3.6.2
#> Warning: package 'tibble' was built under R version 3.6.2
#> Warning: package 'tidyr' was built under R version 3.6.2
#> Warning: package 'purrr' was built under R version 3.6.2
#> Warning: package 'dplyr' was built under R version 3.6.2

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

iallum commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

fdicera commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

bensoltoff commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os macOS Catalina 10.15.5 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2020-07-09 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> backports 1.1.7 2020-05-13 [1] CRAN (R 4.0.0) #> blob 1.2.1 2020-01-20 [1] CRAN (R 4.0.0) #> broom 0.5.6 2020-04-20 [1] CRAN (R 4.0.0) #> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0) #> cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.0) #> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> curl 4.3 2019-12-02 [1] CRAN (R 4.0.0) #> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.0) #> dbplyr 1.4.4 2020-05-27 [1] CRAN (R 4.0.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0) #> dplyr * 1.0.0 2020-05-29 [1] CRAN (R 4.0.0) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0) #> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0) #> forcats * 0.5.0 2020-03-01 [1] CRAN (R 4.0.0) #> fs 1.4.1 2020-04-04 [1] CRAN (R 4.0.0) #> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.0) #> ggplot2 * 3.3.1 2020-05-28 [1] CRAN (R 4.0.0) #> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0) #> haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> hms 0.5.3 2020-01-08 [1] CRAN (R 4.0.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 4.0.0) #> httr 1.4.1 2019-08-05 [1] CRAN (R 4.0.0) #> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 4.0.0) #> knitr 1.28 2020-02-06 [1] CRAN (R 4.0.0) #> labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0) #> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.0) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0) #> lubridate 1.7.8 2020-04-06 [1] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0) #> mime 0.9 2020-02-04 [1] CRAN (R 4.0.0) #> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0) #> nlme 3.1-148 2020-05-24 [1] CRAN (R 4.0.0) #> pillar 1.4.4 2020-05-05 [1] CRAN (R 4.0.0) #> pkgbuild 1.0.8 2020-05-07 [1] CRAN (R 4.0.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0) #> processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0) #> ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.0) #> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0) #> rcfss * 0.1.9 2020-06-24 [1] Github (uc-cfss/rcfss@7ebb53d) #> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0) #> readr * 1.3.1 2018-12-21 [1] CRAN (R 4.0.0) #> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.0) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 4.0.0) #> reprex 0.3.0 2019-05-16 [1] CRAN (R 4.0.0) #> rlang 0.4.6.9000 2020-06-08 [1] Github (r-lib/rlang@10b32e8) #> rmarkdown 2.2 2020-05-31 [1] CRAN (R 4.0.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0) #> rvest 0.3.5 2019-11-08 [1] CRAN (R 4.0.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0) #> stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0) #> tibble * 3.0.1 2020-04-20 [1] CRAN (R 4.0.0) #> tidyr * 1.1.0 2020-05-20 [1] CRAN (R 4.0.0) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0) #> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.0) #> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.0) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0) #> vctrs 0.3.1 2020-06-05 [1] CRAN (R 4.0.1) #> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0) #> xfun 0.14 2020-05-20 [1] CRAN (R 4.0.0) #> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
wmccullen commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os macOS Catalina 10.15.5 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Denver #> date 2020-07-09 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> backports 1.1.8 2020-06-17 [1] CRAN (R 4.0.0) #> blob 1.2.1 2020-01-20 [1] CRAN (R 4.0.0) #> broom 0.5.6 2020-04-20 [1] CRAN (R 4.0.0) #> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0) #> cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.0) #> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> curl 4.3 2019-12-02 [1] CRAN (R 4.0.0) #> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.0) #> dbplyr 1.4.4 2020-05-27 [1] CRAN (R 4.0.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0) #> dplyr * 1.0.0 2020-05-29 [1] CRAN (R 4.0.0) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0) #> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0) #> forcats * 0.5.0 2020-03-01 [1] CRAN (R 4.0.0) #> fs 1.4.1 2020-04-04 [1] CRAN (R 4.0.0) #> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.0) #> ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.0) #> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0) #> haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> hms 0.5.3 2020-01-08 [1] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.0) #> httr 1.4.1 2019-08-05 [1] CRAN (R 4.0.0) #> jsonlite 1.6.1 2020-02-02 [1] CRAN (R 4.0.0) #> knitr 1.28 2020-02-06 [1] CRAN (R 4.0.0) #> labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0) #> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.1) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0) #> lubridate 1.7.9 2020-06-08 [1] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0) #> mime 0.9 2020-02-04 [1] CRAN (R 4.0.0) #> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0) #> nlme 3.1-148 2020-05-24 [1] CRAN (R 4.0.1) #> pillar 1.4.4 2020-05-05 [1] CRAN (R 4.0.0) #> pkgbuild 1.0.8 2020-05-07 [1] CRAN (R 4.0.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0) #> processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0) #> ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.0) #> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0) #> rcfss * 0.1.9 2020-06-29 [1] Github (uc-cfss/rcfss@7ebb53d) #> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0) #> readr * 1.3.1 2018-12-21 [1] CRAN (R 4.0.0) #> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.0) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 4.0.0) #> reprex 0.3.0 2019-05-16 [1] CRAN (R 4.0.0) #> rlang 0.4.6 2020-05-02 [1] CRAN (R 4.0.0) #> rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0) #> rvest 0.3.5 2019-11-08 [1] CRAN (R 4.0.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0) #> stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0) #> tibble * 3.0.1 2020-04-20 [1] CRAN (R 4.0.0) #> tidyr * 1.1.0 2020-05-20 [1] CRAN (R 4.0.0) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0) #> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.0) #> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.0) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0) #> vctrs 0.3.1 2020-06-05 [1] CRAN (R 4.0.0) #> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0) #> xfun 0.15 2020-06-21 [1] CRAN (R 4.0.0) #> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
rammkripa commented 4 years ago

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Catalina 10.15.5 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/London #> date 2020-07-09 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> backports 1.1.8 2020-06-17 [1] CRAN (R 4.0.0) #> blob 1.2.1 2020-01-20 [1] CRAN (R 4.0.0) #> broom 0.5.6 2020-04-20 [1] CRAN (R 4.0.0) #> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0) #> cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.0) #> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> curl 4.3 2019-12-02 [1] CRAN (R 4.0.0) #> DBI 1.1.0 2019-12-15 [1] CRAN (R 4.0.0) #> dbplyr 1.4.4 2020-05-27 [1] CRAN (R 4.0.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0) #> dplyr * 1.0.0 2020-05-29 [1] CRAN (R 4.0.0) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0) #> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0) #> forcats * 0.5.0 2020-03-01 [1] CRAN (R 4.0.0) #> fs 1.4.2 2020-06-30 [1] CRAN (R 4.0.2) #> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.0) #> ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.0) #> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0) #> haven 2.3.1 2020-06-01 [1] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> hms 0.5.3 2020-01-08 [1] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.0) #> httr 1.4.1 2019-08-05 [1] CRAN (R 4.0.0) #> jsonlite 1.7.0 2020-06-25 [1] CRAN (R 4.0.0) #> knitr 1.29 2020-06-23 [1] CRAN (R 4.0.0) #> labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0) #> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0) #> lubridate 1.7.9 2020-06-08 [1] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.0) #> mime 0.9 2020-02-04 [1] CRAN (R 4.0.0) #> modelr 0.1.8 2020-05-19 [1] CRAN (R 4.0.0) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0) #> nlme 3.1-148 2020-05-24 [1] CRAN (R 4.0.2) #> pillar 1.4.4 2020-05-05 [1] CRAN (R 4.0.0) #> pkgbuild 1.0.8 2020-05-07 [1] CRAN (R 4.0.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0) #> processx 3.4.3 2020-07-05 [1] CRAN (R 4.0.2) #> ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.0) #> purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0) #> rcfss * 0.1.9 2020-07-09 [1] Github (uc-cfss/rcfss@7ebb53d) #> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2) #> readr * 1.3.1 2018-12-21 [1] CRAN (R 4.0.0) #> readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.0) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 4.0.0) #> reprex 0.3.0 2019-05-16 [1] CRAN (R 4.0.0) #> rlang 0.4.6 2020-05-02 [1] CRAN (R 4.0.0) #> rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0) #> rvest 0.3.5 2019-11-08 [1] CRAN (R 4.0.0) #> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0) #> stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0) #> tibble * 3.0.2 2020-07-07 [1] CRAN (R 4.0.2) #> tidyr * 1.1.0 2020-05-20 [1] CRAN (R 4.0.0) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0) #> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.0) #> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.0) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0) #> vctrs 0.3.1 2020-06-05 [1] CRAN (R 4.0.0) #> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0) #> xfun 0.15 2020-06-21 [1] CRAN (R 4.0.0) #> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
VanessaGuigon commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

manzoniUC commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

simami1 commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

bensoltoff commented 4 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/Discussion/issues/144

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

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" )

psposa commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

gmeyers405 commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

cweis22 commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.1 (2020-06-06) #> os Red Hat Enterprise Linux 8.2 (Ootpa) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Chicago #> date 2020-07-09 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.1) #> backports 1.1.8 2020-06-17 [2] CRAN (R 4.0.1) #> blob 1.2.1 2020-01-20 [2] CRAN (R 4.0.1) #> broom 0.5.6 2020-04-20 [2] CRAN (R 4.0.1) #> callr 3.4.3 2020-03-28 [2] CRAN (R 4.0.1) #> cellranger 1.1.0 2016-07-27 [2] CRAN (R 4.0.1) #> cli 2.0.2 2020-02-28 [2] CRAN (R 4.0.1) #> colorspace 1.4-1 2019-03-18 [2] CRAN (R 4.0.1) #> crayon 1.3.4 2017-09-16 [2] CRAN (R 4.0.1) #> curl 4.3 2019-12-02 [2] CRAN (R 4.0.1) #> DBI 1.1.0 2019-12-15 [2] CRAN (R 4.0.1) #> dbplyr 1.4.4 2020-05-27 [2] CRAN (R 4.0.1) #> desc 1.2.0 2018-05-01 [2] CRAN (R 4.0.1) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.1) #> digest 0.6.25 2020-02-23 [2] CRAN (R 4.0.1) #> dplyr * 1.0.0 2020-05-29 [1] CRAN (R 4.0.1) #> ellipsis 0.3.1 2020-05-15 [2] CRAN (R 4.0.1) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.1) #> fansi 0.4.1 2020-01-08 [2] CRAN (R 4.0.1) #> farver 2.0.3 2020-01-16 [2] CRAN (R 4.0.1) #> forcats * 0.5.0 2020-03-01 [2] CRAN (R 4.0.1) #> fs 1.4.1 2020-04-04 [2] CRAN (R 4.0.1) #> generics 0.0.2 2018-11-29 [2] CRAN (R 4.0.1) #> ggplot2 * 3.3.1 2020-05-28 [2] CRAN (R 4.0.1) #> glue 1.4.1 2020-05-13 [2] CRAN (R 4.0.1) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.1) #> haven 2.3.1 2020-06-01 [2] CRAN (R 4.0.1) #> highr 0.8 2019-03-20 [2] CRAN (R 4.0.1) #> hms 0.5.3 2020-01-08 [2] CRAN (R 4.0.1) #> htmltools 0.4.0 2019-10-04 [2] CRAN (R 4.0.1) #> httr 1.4.1 2019-08-05 [2] CRAN (R 4.0.1) #> jsonlite 1.6.1 2020-02-02 [2] CRAN (R 4.0.1) #> knitr 1.28 2020-02-06 [2] CRAN (R 4.0.1) #> labeling 0.3 2014-08-23 [2] CRAN (R 4.0.1) #> lattice 0.20-41 2020-04-02 [2] CRAN (R 4.0.1) #> lifecycle 0.2.0 2020-03-06 [2] CRAN (R 4.0.1) #> lubridate 1.7.9 2020-06-08 [2] CRAN (R 4.0.1) #> magrittr 1.5 2014-11-22 [2] CRAN (R 4.0.1) #> memoise 1.1.0 2017-04-21 [2] CRAN (R 4.0.1) #> mime 0.9 2020-02-04 [2] CRAN (R 4.0.1) #> modelr 0.1.8 2020-05-19 [2] CRAN (R 4.0.1) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.1) #> nlme 3.1-148 2020-05-24 [2] CRAN (R 4.0.1) #> pillar 1.4.4 2020-05-05 [2] CRAN (R 4.0.1) #> pkgbuild 1.0.8 2020-05-07 [2] CRAN (R 4.0.1) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.1) #> pkgload 1.1.0 2020-05-29 [2] CRAN (R 4.0.1) #> prettyunits 1.1.1 2020-01-24 [2] CRAN (R 4.0.1) #> processx 3.4.2 2020-02-09 [2] CRAN (R 4.0.1) #> ps 1.3.3 2020-05-08 [2] CRAN (R 4.0.1) #> purrr * 0.3.4 2020-04-17 [2] CRAN (R 4.0.1) #> R6 2.4.1 2019-11-12 [2] CRAN (R 4.0.1) #> rcfss * 0.1.9 2020-06-29 [1] Github (uc-cfss/rcfss@7ebb53d) #> Rcpp 1.0.4.6 2020-04-09 [2] CRAN (R 4.0.1) #> readr * 1.3.1 2018-12-21 [2] CRAN (R 4.0.1) #> readxl 1.3.1 2019-03-13 [2] CRAN (R 4.0.1) #> remotes 2.1.1 2020-02-15 [2] CRAN (R 4.0.1) #> reprex 0.3.0 2019-05-16 [2] CRAN (R 4.0.1) #> rlang 0.4.6 2020-05-02 [2] CRAN (R 4.0.1) #> rmarkdown 2.2 2020-05-31 [2] CRAN (R 4.0.1) #> rprojroot 1.3-2 2018-01-03 [2] CRAN (R 4.0.1) #> rvest 0.3.5 2019-11-08 [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.4.6 2020-02-17 [2] CRAN (R 4.0.1) #> stringr * 1.4.0 2019-02-10 [2] CRAN (R 4.0.1) #> testthat 2.3.2 2020-03-02 [2] CRAN (R 4.0.1) #> tibble * 3.0.1 2020-04-20 [2] CRAN (R 4.0.1) #> tidyr * 1.1.0 2020-05-20 [2] CRAN (R 4.0.1) #> tidyselect 1.1.0 2020-05-11 [2] CRAN (R 4.0.1) #> tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 4.0.1) #> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.1) #> utf8 1.1.4 2018-05-24 [2] CRAN (R 4.0.1) #> vctrs 0.3.1 2020-06-05 [2] CRAN (R 4.0.1) #> withr 2.2.0 2020-04-20 [2] CRAN (R 4.0.1) #> xfun 0.14 2020-05-20 [2] CRAN (R 4.0.1) #> xml2 1.3.2 2020-04-23 [2] CRAN (R 4.0.1) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.1) #> #> [1] /home/cweis22/R/x86_64-pc-linux-gnu-library/4.0 #> [2] /opt/R/4.0.1/lib/R/library ```
kathleencannell commented 4 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/Discussion/issues/144

library(tidyverse)

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

# load the data
data("mass_shootings")
mass_shootings
#> # A tibble: 114 x 14
#>    case   year month   day location summary fatalities injured total_victims
#>    <chr> <dbl> <chr> <int> <chr>    <chr>        <dbl>   <dbl>         <dbl>
#>  1 Dayt…  2019 Aug       4 Dayton,… "PENDI…          9      27            36
#>  2 El P…  2019 Aug       3 El Paso… "PENDI…         20      26            46
#>  3 Gilr…  2019 Jul      28 Gilroy,… "Santi…          3      12            15
#>  4 Virg…  2019 May      31 Virgini… "DeWay…         12       4            16
#>  5 Harr…  2019 Feb      15 Aurora,… "Gary …          5       6            11
#>  6 Penn…  2019 Jan      24 State C… "Jorda…          3       1             4
#>  7 SunT…  2019 Jan      23 Sebring… "Zephe…          5       0             5
#>  8 Merc…  2018 Nov      19 Chicago… "Juan …          3       0             3
#>  9 Thou…  2018 Nov       7 Thousan… "Ian D…         12      22            34
#> 10 Tree…  2018 Oct      27 Pittsbu… "Rober…         11       6            17
#> # … with 104 more rows, and 5 more variables: location_type <chr>, male <lgl>,
#> #   age_of_shooter <dbl>, race <chr>, prior_mental_illness <chr>

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

# using 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 2020-07-09 by the reprex package (v0.3.0)