#Install and load required packages
if (!require("dplyr")) install.packages("dplyr")
## Loading required package: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
if (!require("tidyverse")) install.packages("tidyverse")
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.3 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── 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(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")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(mydata, aes(x = MedIncome))+geom_histogram(color="black",fill="dodgerblue")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#Compute descriptive statistics for PctBB and MedIncome
mydata %>%
select(PctBB, MedIncome) %>%
summarise_all(list(Median = median,
Mean = mean,
SD = sd,
Min = min,
Max = max))
## PctBB_Median MedIncome_Median PctBB_Mean MedIncome_Mean PctBB_SD MedIncome_SD
## 1 71.9 44122 72.22947 47167 7.045458 10837.72
## PctBB_Min MedIncome_Min PctBB_Max MedIncome_Max
## 1 51.2 30136 93.4 112962
#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)
## `geom_smooth()` using formula = 'y ~ x'
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.