#Q1

#loading libraries
library(ggplot2)
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
#load the data 
data(tract_covariates)
## Warning in data(tract_covariates): data set 'tract_covariates' not found
tract_covariates<- read.csv("C:/Users/عمر/Desktop/Fall 2024/Rstudio/Week 5/tract_covariates.csv")


#Q2

dataframe <- tract_covariates[, c("czname", "hhinc_mean2000", "popdensity2000")]

#Q3

San_Antonio_DF <- dataframe[dataframe$czname == "San Antonio", ]


#Q4

ggplot(San_Antonio_DF, aes(x = hhinc_mean2000, fill = czname)) + 
  geom_histogram(binwidth = 5000, position = "identity", alpha = 0.9)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

#Q5

ggplot(San_Antonio_DF, aes(x = czname, y = popdensity2000, fill = czname)) + 
  geom_boxplot()

#Q6

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

#Q7

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

#Q8


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

#Q9


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

#Q10


p <- ggplot(San_Antonio_DF, aes(x = popdensity2000, y = hhinc_mean2000)) + 
  geom_point() +
  labs(x = "Population Density",y = "Household Income")

ggplotly(p)