Objectives

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.

Look at the data

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 ...

1. First plot

# place code for vis here
v1 = housing%>%
  group_by(Infl, Type, Cont)%>%
  summarise(Freq = sum(Freq))
levels(v1$Infl) = list('Influence-Low' = 'Low', 'Influence-Medium' = 'Medium', 'Influence-High' = 'High')
levels(v1$Cont) = list('Contact-Low' = 'Low', 'Contact-High' = 'High')
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 3.6.2
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
ggballoonplot(v1, x = 'Infl', y = 'Cont', size = 'Freq', facet.by = 'Type',
              fill = 'Freq', ggtheme = theme_light()) +
  scale_fill_viridis_c(option = 'A')

## Conclusion - from the above graph, we can see that most tenants lived in apartments while least inhabitants from atrium. More people had low seen degree on the management of the property and high contact managed with different occupants.

2. Second plot

# place code for vis here
v2 = housing %>%
  group_by(Sat, Type) %>%
  summarise(Freq = sum(Freq))

ggplot(v2, aes(Freq, Sat)) +
  geom_point(aes(color = Type)) +
  facet_grid(Type ~ ., scales = 'fixed', space = 'fixed') +
  theme_light() +
  theme(strip.text.y = element_text(angle = 0),
        legend.position = 'none') +
  labs(y = 'Satisfaction',
       x = 'Numbers of Residents',
       title = 'Number of Resident by Satisfaction and Rental Accomodation')

## from the above graph, we can see that people living in Tower and Atrium have higher satisfaction than lower satisfaction.

3. Third plot

# place code for vis here
v3 = housing %>%
  group_by(Sat, Type, Infl) %>%
  summarise(Freq = sum(Freq))
levels(v3$Infl) = list('Inf-Low' = 'Low', 'Inf-Medium' = 'Medium', 'Inf-High' = 'High')

ggplot(v3, aes(x = Infl, y = Freq))+
  geom_bar(
    aes(fill = Sat), stat = 'identity', color = 'black',
    position = position_dodge(0.9)
  ) +
  theme_light() +
  facet_wrap(~Type) +
  guides(fill = guide_legend(title = 'Satisfaction')) +
  labs(x = 'Influence of Management',
       y = 'Numbers of Residents',
       title = 'Number of Resident by Satisfaction, Rental Accomodation and Management Influence') + 
  scale_fill_manual(name = 'Number of Resident by Satisfaction, Rental Accomodation and Management Influence', 
                    labels = c('Influence-Low', 'Influence-Medium', 'Influence-High'),
                    values = c('azure2', 'azure3', 'azure4'))

## For a wide range of rental convenience, people always have higher satisfaction when they had higher degree of influence on the management of the property. Particularly for people living in Apartment and Terrace, the greater part of these occupants had low satisfaction when impact or the influence was low, while the greater part of them had high satisfaction when impact or influence was high.

4. Fourth plot

# place code for vis here
ggplot(housing,aes(Infl, Freq))+
  geom_bar(
    aes(fill = Cont),stat = "identity",
  )+
  facet_wrap(~Type)

## Conlcusion - from the above graph, most people living in in atrium and Terrace properties hold a low perceived degree of influence householders on the management of the property. 

5. Fifth plot

# place code for vis here
v5 <- housing %>%
  mutate(
    sum_sat_score = ifelse(Sat == 'Low', 1, ifelse(Sat == 'High', 5, 3)) * Freq
  ) %>%
  group_by(Infl, Cont, Type) %>%
  summarise(
    sum_sat_score = sum(sum_sat_score),
    Freq = sum(Freq)
  ) %>%
  mutate(avg_sat_score = round(sum_sat_score / Freq, 2))

ggplot(v5, aes(Infl, avg_sat_score)) +
  facet_wrap(Type ~ .) +
  geom_bar(
    aes(fill = Cont), stat = "identity", color = "white",
    position = position_dodge(0.9)
  )  +
  guides(fill = guide_legend(title = "Afforded Contact")) +
  labs(x = "Mangement Influence",
       y = "Avg Satisfaction Score",
       title = "Resident Satisfaction by Rental Accomodation, Management Influence and Afforded Contact")

##The average satsfaction scores among the tower resident have the smallest gap (3 ~ 4.5), while Apartment residents’ satisfaction has the biggest gap (2 ~ 4) depending on Management Influence and Afforded Contact.