The objective of this assignment is to conduct an exploratory data analysis of a data set that you are not familiar with. In this week’s lecture, we discussed a number of visualization approaches in order to explore a data set with categorical variables. This assignment will apply those tools and techniques. An important distinction between class examples and applied data science work is iterative and repetitive nature of exploring a data set. It takes time to understand what the data is and what is interesting about the data (patterns).
For this week, we will be exploring the Copenhagen Housing Conditions Survey:
Your task for this assignment is to use ggplot and the facet_grid and facet_wrap functions to explore the Copenhagen Housing Conditions Survey. Your objective is to develop 5 report quality visualizations (at least 4 of the visualizations should use the facet_wrap or facet_grid functions) and identify interesting patterns and trends within the data that may be indicative of large scale trends. For each visualization you need to write a few sentences about the trends and patterns that you discover from the visualization.
To submit this homework you will create the document in Rstudio, using the knitr package (button included in Rstudio) and then submit the document to your Rpubs account. Once uploaded you will submit the link to that document on Canvas. Please make sure that this link is hyperlinked and that I can see the visualization and the code required to create it.
str(housing)
## 'data.frame': 72 obs. of 5 variables:
## $ Sat : Ord.factor w/ 3 levels "Low"<"Medium"<..: 1 2 3 1 2 3 1 2 3 1 ...
## $ Infl: Factor w/ 3 levels "Low","Medium",..: 1 1 1 2 2 2 3 3 3 1 ...
## $ Type: Factor w/ 4 levels "Tower","Apartment",..: 1 1 1 1 1 1 1 1 1 2 ...
## $ Cont: Factor w/ 2 levels "Low","High": 1 1 1 1 1 1 1 1 1 1 ...
## $ Freq: int 21 21 28 34 22 36 10 11 36 61 ...
ggplot(housing, aes(x=Infl, y=Freq)) + geom_point(shape=1)
facet_grid(Type~Sat)
## <ggproto object: Class FacetGrid, Facet, gg>
## compute_layout: function
## draw_back: function
## draw_front: function
## draw_labels: function
## draw_panels: function
## finish_data: function
## init_scales: function
## map_data: function
## params: list
## setup_data: function
## setup_params: function
## shrink: TRUE
## train_scales: function
## vars: function
## super: <ggproto object: Class FacetGrid, Facet, gg>
ggplot(housing) +
geom_bar(aes(x = Cont, y = Freq, fill = Sat), stat = 'identity', width =.6, position = "dodge") +
labs(title="Resident Numbers by Satisfaction & Rental Type ") +
labs(fill = "Satisfaction") +
xlab("Contact") +
ylab("Resident Numbers") +
facet_wrap(~Type)
ggplot(housing, aes(x = Sat, y = Freq))+
geom_bar(
aes(fill = Cont), stat = "identity", color = "green",
position = position_dodge(0.5)
)+
facet_wrap(~Type)
H=housing %>%
group_by(Type, Cont) %>%
summarise(Freq = sum(Freq))
ggplot(H, aes(Cont, Freq)) +
geom_point(aes(color = Type)) +
facet_grid(Type ~ ., scales = "free", space = "free") +
theme_light() +
theme(strip.text.y = element_text(angle = 0),
legend.position = "none") +
labs(y = "Residents Numbers",
x = "Type",
title = "Type",
subtitle = "Number of residents by cost shared")
H2= housing %>%
group_by(Infl, Cont) %>%
summarise(Freq = sum(Freq))
ggplot(H2, aes(Cont, Freq)) +
geom_point(aes(color = Infl)) +
facet_grid(Infl ~ ., scales = "free", space = "free") +
theme_light() +
theme(strip.text.y = element_text(angle = 0),
legend.position = "none") +
labs(y = "Resident Number",
x = "Perceived Influence",
title = "Resident Perceived Influence",
subtitle = "Number of residents by cost shared with others")