library(ggplot2)

data <- read.csv("https://opportunityinsights.org/wp-content/uploads/2018/10/tract_covariates.csv")

df1 <- data[, c("czname", "hhinc_mean2000", "popdensity2000")]

san_antonio <- df1[df1$czname == "San Antonio", ]

ggplot(san_antonio, aes(x = hhinc_mean2000)) + 
  geom_histogram(binwidth = 1000, fill = "navyblue", color = "black") +
  labs(title = "Household Income Distribution in San Antonio (2000)",
       x = "Household Income (2000)",
       y = "Number of Census Tracts")
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

ggplot(san_antonio, aes(y = popdensity2000)) +
  geom_boxplot(fill = "lightblue", color = "black") +
  labs(title = "Population Density Distribution in San Antonio (2000)", 
       y = "Population Density (2000)",
       x = "")

ggplot(san_antonio, aes(x = hhinc_mean2000)) + 
  geom_density(fill = "royalblue", color = "black") + 
  labs(title = "Probability Density of Household Income in San Antonio (2000)", 
       x = "Household Income (2000)", 
       y = "Density") 
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_density()`).

ggplot(san_antonio, aes(x = hhinc_mean2000)) + 
  stat_ecdf(geom = "step", color = "cyan") +
  labs(title = "Cumulative Density of Household Income in San Antonio (2000)", 
       x = "Household Income (2000)", 
       y = "Cumulative Probability") 
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_ecdf()`).

ggplot(san_antonio, aes(x = popdensity2000, y = hhinc_mean2000)) + 
  geom_point(color = "darkblue") + 
  labs(title = "Scatter Plot of Population Density vs Household Income in San Antonio (2000)",
       x = "Population Density (2000)", 
       y = "Household Income (2000)")
## 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
p <- ggplot(san_antonio, aes(x = popdensity2000, y = hhinc_mean2000)) + 
  geom_point(color = "purple") +
  labs(title = "Scatter Plot of Population Density vs Household Income in San Antonio (2000)",
       x = "Population Density (2000)", 
       y = "Household Income (2000)")
interactive_plot <- ggplotly(p)
interactive_plot