This code will generate descriptive statistics and selected charts for the PctBB and MedIncome variables in the TNAccessData.csv example dataset. Follow the example dataset link for an R script that will retrieve the dataset and store it on your computer.
#Install and load required packages
if (!require("dplyr")) install.packages("dplyr")
if (!require("tidyverse")) install.packages("tidyverse")
library(dplyr)
library(ggplot2)
#Read the data
mydata <- read.csv("TNBBAccessData.csv")
#Look at histograms of the PctBB and MedIncome distributions
ggplot(mydata, aes(x = PctBB))+geom_histogram(color="black",fill="dodgerblue")
ggplot(mydata, aes(x = MedIncome))+geom_histogram(color="black",fill="dodgerblue")
#Compute descriptive statistics for PctBB and MedIncome
mydata %>%
select(PctBB, MedIncome) %>%
summarise_all(list(Median = median,
Mean = mean,
SD = sd,
Min = min,
Max = max))
#Look at a scatterplot of PctBB and MedIncome
ggplot(mydata,aes(x = MedIncome,
y = PctBB))+
geom_point(size = 2)+
geom_smooth(method = "lm",
se = FALSE)