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

Residents’ infl vs cont

# place code for vis here
data1=housing %>% 
  group_by(Infl, Type, Cont) %>%
  summarise(Freq=sum(Freq))


ggplot(data1,aes(x=Infl, y=Freq))+ 
         geom_bar(aes(fill=Cont),stat='identity', position=position_dodge(0.9))+
         facet_wrap(~Type)+
         labs(x="Influence on Management",
              y="Number of Residents",
              title="Residents' count by Influence on Management, Rental Accomodation Type, and Satisfaction")

2. Second plot

# place code for vis here
data2=housing %>% 
  group_by(Type, Cont, Sat) %>%
  summarize(Freq=sum(Freq))

levels(data2$Sat) = list('Sat-Low' = 'Low', 'Sat-Medium' = 'Medium', 'Sat-High' = 'High')
levels(data2$Cont) = list('Contact-Low' = 'Low', 'Contact-High' = 'High')


ggballoonplot(data2,x="Cont",y="Sat", size="Freq", facet.by="Type",fill="Freq",ggtheme=theme_light())+ 
         scale_fill_viridis_c(option="A")

3. Third plot

# place code for vis here

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

ggplot(data3, aes(Freq, Sat)) +
  geom_bar(aes(fill=Type),stat='identity', position=position_dodge(0.9))+
  facet_grid(Type ~ ., scales = 'fixed', space = 'fixed') +
  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')

4. Fourth plot

# place code for vis here
data4 = housing %>%
  group_by(Type, Cont,Infl) %>%
  summarise(Freq = sum(Freq))

levels(data4$Infl) = list('Sat-Low' = 'Low', 'Sat-Medium' = 'Medium', 'Sat-High' = 'High')
levels(data4$Cont) = list('Contact-Low' = 'Low', 'Contact-High' = 'High')

ggplot(data4, aes(Freq, Cont)) +
  geom_point(aes(color=Type))+
  facet_grid(Type ~ Infl, space="fixed", scales="fixed") +
  theme(strip.text.y = element_text(angle = 0),
        legend.position = 'none') +
  labs(y = 'Afforded Contact',
       x = 'Numbers of Residents',
       title = 'Number of Resident by Afforded Contact, Management Influence, and Rental Accomodation')

5. Fifth plot

# place code for vis here
data5 = housing %>%
  mutate( stat_score=ifelse(Sat=="Low",1,ifelse(Sat=="High",3,2))* Freq
  )%>%
  group_by(Type,Infl)%>%
  summarise( 
    stat_score=sum(stat_score),
    Freq=sum(Freq)
  )%>%
  mutate(average=round(stat_score/Freq,2))

# Freq, average score, Type, Infl


ggplot(data5,aes(x=average, y=Infl))+ 
         geom_point(aes(size=Freq,color=Freq))+
           facet_grid(Type ~ .) +
         labs(x="Agerage Sat Scores",
              y="Management Influence",
              title="Residents' count by Influence on Management, Rental Accomodation Type, and Average Satisfaction Scores")