library(ggplot2)

#Q1
data<-read.csv("https://opportunityinsights.org/wp-content/uploads/2018/10/tract_covariates.csv")
#Q2
d1 <- data[, c("czname", "hhinc_mean2000", "popdensity2000")]

#Q3
d2 <- d1[d1$czname == 'San Antonio', ]
#Q4
ggplot(d2, aes(x = hhinc_mean2000)) + 
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

#Q5
ggplot(d2, aes(y = popdensity2000)) + 
  geom_boxplot()

#Q6
ggplot(d2, aes(x = hhinc_mean2000)) + geom_density()
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_density()`).

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

#Q8
ggplot(d2, aes(x= hhinc_mean2000 , y = popdensity2000)) + 
  geom_point()+ 
  labs(x = "hhinc_mean2000", y = "popdensity2000")
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

#Q9
ggplot(d2, aes(x =hhinc_mean2000)) + 
  stat_ecdf()+
  labs(x = "mean household income 2000", y="CDF")
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_ecdf()`).

#Q10
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
n <- ggplot(d2, aes(x = hhinc_mean2000, y = popdensity2000)) + 
  geom_point()

ggplotly(n)