library(tidyverse)
## ── 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.1
## ✔ 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(dplyr)
library(knitr)
dataset<-read_csv("dataset_final.csv")
## New names:
## Rows: 51 Columns: 7
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," chr
## (1): State dbl (6): ...1, Spending_per_enrollee, 65-74 Population, 75-84
## Population, 85...
## ℹ 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.
## • `` -> `...1`
dataset<-dataset[,-1]
str(dataset)
## tibble [51 × 6] (S3: tbl_df/tbl/data.frame)
## $ State : chr [1:51] "ALABAMA" "ALASKA" "ARIZONA" "ARKANSAS" ...
## $ Spending_per_enrollee: num [1:51] 10688 9939 10092 9919 12586 ...
## $ 65-74 Population : num [1:51] 541944 66426 783000 315422 3558013 ...
## $ 75-84 Population : num [1:51] 261671 24499 416355 158588 1721688 ...
## $ 85+ Population : num [1:51] 85202 6738 133691 54091 677391 ...
## $ Total_Deaths : num [1:51] 3792 254 5295 2427 23452 ...
dataset_graph<-ggplot(dataset, aes(x =`Spending_per_enrollee`, y =`Total_Deaths`)) +
geom_point(alpha = 0.5)+
scale_x_continuous(breaks = pretty(dataset$Total_Deaths, n=10))+
labs(title = "Mortality Rates by Healthcare Spending", x= "Medicare Funding Spent", y= "Total Deaths") +
theme_minimal()
dataset_graph

dataset_mortality<- dataset %>%
mutate(Population_over_65=dataset$`65-74 Population`+ dataset$`75-84 Population`+ dataset$`85+ Population`) %>%
mutate(Mortality_rate=(Total_Deaths/Population_over_65)*100)
dataset_table<- kable(dataset_mortality, digits = c(0,2,0,0,0,0,0,2),
col.names = c("State", "Medicare Spending per Enrollee",
"65-74 Population", "75-84 Population",
"85+ Population","Total Deaths",
"Population over 65", "Mortality Rate"),
caption = "Mortality for Selected Causes and Medicare
Spending by State in 2018")
dataset_table
Mortality for Selected Causes and Medicare Spending by State in
2018
ALABAMA |
10687.68 |
541944 |
261671 |
85202 |
3792 |
888817 |
0.43 |
ALASKA |
9938.61 |
66426 |
24499 |
6738 |
254 |
97663 |
0.26 |
ARIZONA |
10092.20 |
783000 |
416355 |
133691 |
5295 |
1333046 |
0.40 |
ARKANSAS |
9918.67 |
315422 |
158588 |
54091 |
2427 |
528101 |
0.46 |
CALIFORNIA |
12586.06 |
3558013 |
1721688 |
677391 |
23452 |
5957092 |
0.39 |
COLORADO |
9452.91 |
558844 |
239521 |
81288 |
2237 |
879653 |
0.25 |
CONNECTICUT |
12200.54 |
378532 |
190277 |
80426 |
1680 |
649235 |
0.26 |
DELAWARE |
11418.66 |
124397 |
58586 |
18663 |
568 |
201646 |
0.28 |
DISTRICT OF COLUMBIA |
11308.70 |
50717 |
24518 |
10603 |
397 |
85838 |
0.46 |
FLORIDA |
12170.40 |
2591258 |
1470807 |
536321 |
15009 |
4598386 |
0.33 |
GEORGIA |
10686.99 |
987987 |
455027 |
141057 |
6459 |
1584071 |
0.41 |
HAWAII |
7472.03 |
162622 |
80866 |
38816 |
800 |
282304 |
0.28 |
IDAHO |
8929.01 |
197346 |
90494 |
27616 |
1003 |
315456 |
0.32 |
ILLINOIS |
11283.33 |
1259846 |
601395 |
240221 |
6824 |
2101462 |
0.32 |
INDIANA |
10757.30 |
681528 |
316728 |
116432 |
4258 |
1114688 |
0.38 |
IOWA |
9853.68 |
336104 |
159823 |
69346 |
2110 |
565273 |
0.37 |
KANSAS |
10533.20 |
294178 |
137320 |
58140 |
1954 |
489638 |
0.40 |
KENTUCKY |
10120.59 |
476140 |
220507 |
73613 |
2927 |
770260 |
0.38 |
LOUISIANA |
11650.01 |
471409 |
216146 |
74255 |
3102 |
761810 |
0.41 |
MAINE |
9158.84 |
183139 |
84057 |
29969 |
1113 |
297165 |
0.37 |
MARYLAND |
11898.85 |
604486 |
289158 |
109513 |
3185 |
1003157 |
0.32 |
MASSACHUSETTS |
11661.35 |
726907 |
346225 |
141561 |
2993 |
1214693 |
0.25 |
MICHIGAN |
10879.44 |
1118078 |
517196 |
187508 |
7179 |
1822782 |
0.39 |
MINNESOTA |
11489.31 |
577187 |
268593 |
109903 |
2873 |
955683 |
0.30 |
MISSISSIPPI |
11428.40 |
303969 |
142839 |
47436 |
3155 |
494244 |
0.64 |
MISSOURI |
10477.43 |
649461 |
315255 |
119051 |
3446 |
1083767 |
0.32 |
MONTANA |
8648.68 |
135439 |
60197 |
20787 |
515 |
216423 |
0.24 |
NEBRASKA |
10669.59 |
193977 |
89882 |
38031 |
1254 |
321890 |
0.39 |
NEVADA |
11120.74 |
321908 |
154041 |
42518 |
2216 |
518467 |
0.43 |
NEW HAMPSHIRE |
9369.38 |
166691 |
73406 |
27424 |
643 |
267521 |
0.24 |
NEW JERSEY |
12394.35 |
920871 |
458662 |
186384 |
4235 |
1565917 |
0.27 |
NEW MEXICO |
8665.11 |
238520 |
114957 |
38469 |
1235 |
391946 |
0.32 |
NEW YORK |
13138.75 |
2037717 |
1011298 |
428706 |
13206 |
3477721 |
0.38 |
NORTH CAROLINA |
10106.07 |
1101147 |
520528 |
171639 |
6170 |
1793314 |
0.34 |
NORTH DAKOTA |
11304.07 |
73642 |
34310 |
16689 |
436 |
124641 |
0.35 |
OHIO |
10629.95 |
1278292 |
593832 |
226875 |
8008 |
2098999 |
0.38 |
OKLAHOMA |
11332.89 |
388432 |
189996 |
66283 |
5433 |
644711 |
0.84 |
OREGON |
8609.80 |
489637 |
224253 |
74489 |
2481 |
788379 |
0.31 |
PENNSYLVANIA |
10590.53 |
1465176 |
706858 |
292420 |
7656 |
2464454 |
0.31 |
RHODE ISLAND |
9737.28 |
118373 |
56012 |
24406 |
577 |
198791 |
0.29 |
SOUTH CAROLINA |
10257.25 |
600896 |
281831 |
83672 |
3444 |
966399 |
0.36 |
SOUTH DAKOTA |
11399.19 |
97689 |
40563 |
18166 |
565 |
156418 |
0.36 |
TENNESSEE |
9889.50 |
728268 |
345555 |
111449 |
5860 |
1185272 |
0.49 |
TEXAS |
11963.65 |
2408573 |
1097502 |
369909 |
14633 |
3875984 |
0.38 |
UTAH |
9774.65 |
242367 |
111129 |
35652 |
1281 |
389148 |
0.33 |
VERMONT |
9206.11 |
82540 |
37555 |
13163 |
406 |
133258 |
0.30 |
VIRGINIA |
9474.86 |
853298 |
412369 |
140985 |
4376 |
1406652 |
0.31 |
WASHINGTON |
8736.53 |
782531 |
352000 |
120647 |
4336 |
1255178 |
0.35 |
WEST VIRGINIA |
10508.27 |
226067 |
107444 |
35909 |
1782 |
369420 |
0.48 |
WISCONSIN |
10212.38 |
649145 |
295589 |
112509 |
3158 |
1057243 |
0.30 |
WYOMING |
9975.40 |
65986 |
28167 |
9724 |
321 |
103877 |
0.31 |
<<<<<<< HEAD
high_mortality_low_spending <- dataset_mortality %>%
filter(
Total_Deaths > median(dataset_mortality$Total_Deaths, na.rm = TRUE) &
Spending_per_enrollee < median(dataset_mortality$Spending_per_enrollee, na.rm = TRUE)
)
ggplot(high_mortality_low_spending, aes(x = reorder(State, -Total_Deaths), y = Total_Deaths)) +
geom_bar(stat = "identity", fill = "steelblue") +
coord_flip() +
labs(
title = "States with High Mortality and Low Spending",
x = "State",
y = "Mortality Rate (per 100,000)",
caption = "Data source: KFF, CDC Wonder"
) +
theme_minimal()

ggplot(dataset_mortality, aes(x = reorder(State, -Total_Deaths), y = Total_Deaths)) +
geom_bar(stat = "identity", fill = "steelblue", width = 0.8) +
coord_flip() +
labs(
title = "Total Deaths by State",
x = "State",
y = "Total Deaths",
caption = "Data source: KFF, CDC Wonder"
) +
theme_minimal() +
theme(
axis.text.y = element_text(size = 8),
plot.margin = margin(10, 20, 10, 20)
)
