# Load necessary libraries
library(readr)
library(dplyr)
library(ggplot2)
library(tidyr)
library(broom)
library(ggthemes) # Required for theme_hc()
You can also embed plots, for example:
```{colnames(cancer_data) <- gsub(“\.”, “_“, make.names(colnames(cancer_data)))}
cancer_data_clean <- cancer_data %>% filter(Total_Rate > 0, Rates_Race_White > 0, Rates_Race_Black > 0) %>% mutate(Population_Size = case_when( Total_Population < quantile(Total_Population, 0.33) ~ “Small State”, Total_Population < quantile(Total_Population, 0.66) ~ “Medium State”, TRUE ~ “Large State” )) %>% mutate(Population_Size = factor(Population_Size, levels = c(“Small State”, “Medium State”, “Large State”)))
ggplot(cancer_data_clean, aes(x = Population_Size, y = Total_Rate, fill = Population_Size)) + geom_boxplot(alpha = 0.7, outlier.color = “red”) + geom_jitter(color = “black”, width = 0.1, alpha = 0.3) + scale_fill_manual(values = c(“Small State” = “#E69F00”, “Medium State” = “#56B4E9”, “Large State” = “#009E73”)) + labs( title = “Cancer Rate Distribution by State Population”, x = “Population Category”, y = “Total Mortality Rate”, fill = “Category” ) + theme_minimal()
```{ggplot(cancer_data_clean, aes(x = Rates_Race_Black, y = Total_Rate, color = Population_Size)) +}
geom_point(size = 3, alpha = 0.8) +
geom_smooth(method = "lm", se = TRUE, color = "black", linetype = "dashed") +
scale_color_manual(values = c("Small State" = "#E69F00",
"Medium State" = "#56B4E9",
"Large State" = "#009E73")) +
labs(
title = "Impact of Black Mortality on Total Cancer Rates",
subtitle = "Linear Regression Analysis",
x = "Black Cancer Mortality Rate (per 100k)",
y = "Total Cancer Mortality Rate (per 100k)",
color = "State Size",
caption = "Source: CDC via CORGIS"
) +
theme_minimal()
ggplot(cancer_data_clean, aes(x = Population_Size, y = Total_Rate, fill = Population_Size)) +
geom_boxplot(alpha = 0.7, outlier.color = "red") +
geom_jitter(color = "black", width = 0.1, alpha = 0.3) +
scale_fill_manual(values = c("Small State" = "#E69F00",
"Medium State" = "#56B4E9",
"Large State" = "#009E73")) +
labs(
title = "Cancer Rate Distribution by State Population",
x = "Population Category",
y = "Total Mortality Rate",
fill = "Category",
caption = "Source: CDC via CORGIS"
) +
theme_minimal()