knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
url <- "https://opportunityinsights.org/wp-content/uploads/2018/10/tract_covariates.csv"
data <- read.csv(url)
df <- data[, c("czname", "hhinc_mean2000", "popdensity2000")]
dfsa <- df[df$czname == "San Antonio", ]
ggplot(dfsa, aes(x = hhinc_mean2000)) +
geom_histogram(binwidth = 5000, fill = "blue", color = "black")
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

ggplot(dfsa, aes(y = popdensity2000)) +
geom_boxplot(fill = "orange", color = "black")

ggplot(dfsa, aes(x = hhinc_mean2000)) +
geom_density(fill = "green", alpha = 0.5)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_density()`).

ggplot(dfsa, aes(x = hhinc_mean2000)) +
stat_ecdf(geom = "step", color = "red")
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_ecdf()`).

scatterplot <- ggplot(dfsa, aes(x = popdensity2000, y = hhinc_mean2000)) +
geom_point(color = "purple") +
labs(x = "Population Density (2000)", y = "Household Income (2000)")
print(scatterplot)
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

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
interactive_plot <- ggplotly(scatterplot)
interactive_plot