── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.0 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)library(scales)
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
library(tidycensus) library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(leaflet) library(usdata) library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
install =TRUEcensus_api_key("")
To install your API key for use in future sessions, run this function with `install = TRUE`.
states <-get_acs(geography ="state", variables ="B01003_001", geometry =TRUE, shift_geo = T)
Getting data from the 2018-2022 5-year ACS
Warning: The `shift_geo` argument is deprecated and will be removed in a future
release. We recommend using `tigris::shift_geometry()` instead.
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.
Using feature geometry obtained from the albersusa package
Please note: Alaska and Hawaii are being shifted and are not to scale.
old-style crs object detected; please recreate object with a recent sf::st_crs()
Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
Need '+proj=longlat +datum=WGS84'
Income estimates by state, 2021
homicides <-read_csv("homicides.csv")
Rows: 450 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): STATE, URL
dbl (2): YEAR, RATE
num (1): DEATHS
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
state n
1 AK 60
2 AL 181
3 AR 135
4 AZ 427
5 CA 1325
6 CO 342
7 CT 30
8 DC 29
9 DE 20
10 FL 610
11 GA 358
12 HI 45
13 IA 58
14 ID 83
15 IL 198
16 IN 186
17 KS 92
18 KY 167
19 LA 185
20 MA 59
21 MD 122
22 ME 42
23 MI 173
24 MN 99
25 MO 243
26 MS 128
27 MT 60
28 NC 277
29 ND 20
30 NE 47
31 NH 29
32 NJ 103
33 NM 200
34 NV 159
35 NY 180
36 OH 267
37 OK 251
38 OR 152
39 PA 207
40 RI 8
41 SC 154
42 SD 31
43 TN 268
44 TX 906
45 UT 120
46 VA 173
47 VT 14
48 WA 257
49 WI 152
50 WV 92
51 WY 31
This table shows the number of shootings in each state.