-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mean Household Income by Zip Code.R
34 lines (26 loc) · 1.09 KB
/
Mean Household Income by Zip Code.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Brett Waugh
# 4 October 2017
# 3.2 Exploratory Data Analysis
# Creates a graph of houeshold income and zip code.
# Depends on zipIncome.csv file.
# If you do not already have readr, uncomment the next line.
# install.packages("readr")
#Load readr.
library(readr)
# Remember to fill in file location.
zipIncome <- read_csv("C:/Users/Michael/Downloads/zipIncome.csv")
# Scatter plot of MeanEducation and MeanHouseholdIncome.
x <- zipIncome$MeanEducation # Creates the mean education as x variable.
y <- zipIncome$MeanHouseholdIncome # Creates the mean income as y variable.
# Creates a data frame of x and y.
data <- as.data.frame(cbind(x, y))
# If you do not already have ggplot2, uncomment the next line.
# install.packages("ggplot2")
# Install ggplot2
library(ggplot2)
# Box and Whiskers plot of Mean Household Income by Zip Code
ggplot(data=zipIncome, aes(x=as.factor(Zip1), y=log10(MeanHouseholdIncome))) +
geom_point(aes(color=factor(Zip1)), alpha = 0.2, position ="jitter")+
geom_boxplot(outlier.size=0, alpha=0.1) +
guides(colour=FALSE) +
ggtitle ("Mean Household Income by Zip Code")