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
visual_1 = housing %>%
  group_by(Infl, Type, Cont) %>%
  summarise(Freq = sum(Freq))
levels(visual_1$Infl) = list('Influence-Low' = 'Low', 'Influence-Medium' = 'Medium', 'Influence-High' = 'High')
levels(visual_1$Cont) = list('Contact-Low' = 'Low', 'Contact-High' = 'High')

ggballoonplot(visual_1, x = 'Infl', y = 'Cont', size = 'Freq', facet.by = 'Type',
              fill = 'Freq', ggtheme = theme_light()) +
  scale_fill_viridis_c(option = 'A')

By balance check of every classification, we can see that most occupants associated with the examination lived in apartments while least inhabitants from atrium. More inhabitants had low seen degree on the management of the property and high contact managed with different occupants.

2. Second plot

visual_2 = housing %>%
  group_by(Sat, Type) %>%
  summarise(Freq = sum(Freq))

ggplot(visual_2, 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')

For occupants lived in Tower and Atrium, more individuals would in general have higher satisfaction, while Terrace inhabitants would in general have lower satisfaction Occupants from Apartments had intensely followed satisfaction towards the two sides (high and low).

3. Third plot

visual_3 = housing %>%
  group_by(Sat, Type, Infl) %>%
  summarise(Freq = sum(Freq))
levels(visual_3$Infl) = list('Inf-Low' = 'Low', 'Inf-Medium' = 'Medium', 'Inf-High' = 'High')

ggplot(visual_3, 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, inhabitants would in general have higher satisfaction when they had higher higher perceived degree of influence on the management of the property. Particularly for inhabitants who lived 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

visual_4 = housing %>%
  mutate(
    sum_sat_score = ifelse(Sat == 'Low', 1, ifelse(Sat == 'High', 5, 3)) * Freq
  ) %>%
  group_by(Type, Cont) %>%
  summarise(
    sum_sat_score = sum(sum_sat_score),
    freq = sum(Freq)
  ) %>%
  mutate(avg_sat_score = round(sum_sat_score / freq, 2))

ggplot(visual_4, aes(avg_sat_score, Cont)) +
  geom_point(aes(size = freq, color = freq)) +
  facet_grid(Type ~ .) +
  theme_light() +
  scale_colour_gradient(low = 'yellow', high = 'red') +
  guides(
    size = guide_legend(title = 'Numbers of Residents'),
    color = guide_legend(title = 'Numbers of Residents')
  ) +
  labs(x = 'Average Satisfaction Score',
       y = 'Afforded Contact',
       title = 'Resident Satisfaction by Rental Accomodation and Afforded Contact')

As a rule, the higher the contact the householders were afforded with different inhabitants (Contact), the higher normal satisfaction score. The contrary outcome was seen among Terrace occupants, this outcome may brought about by the littler sample size of Terrace inhabitants who had low afforded contact. (satisfaction score was determined for every householder: 1 for low satisfaction, 3 for medium and 5 for high satisfaction).

5. Fifth plot

visual_5 = 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(visual_5, aes(Infl, avg_sat_score)) +
  facet_wrap(Type ~ .) +
  geom_bar(
    aes(fill = Cont), stat = 'identity', color = 'black',
    position = position_dodge(0.9)
  )  +
  theme_light() +
  guides(fill = guide_legend(title = 'Afforded Contact')) +
  labs(x = 'Mangement Influence',
       y = 'Average Satisfaction Score',
       title = 'Resident Satisfaction by Rental Accomodation, Management Influence and Afforded Contact'
  )  + 
  scale_fill_manual(name = 'Resident Satisfaction by Rental Accomodation, Management Influence and Afforded Contact', 
                    labels = c('Low', 'Medium', 'High'),
                    values = c('azure2', 'azure3', 'azure4'))

The average satisfaction score of tower resident varied the least (3 ~ 4.5), while apartment residents’ satisfaction varied the most (2 ~ 4) depending on Management Influence and Afforded Contact.