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
ggplot(housing,aes(Infl, Freq)) + geom_bar( aes(fill = Cont),stat = "identity",)+   labs(y = 'The numbers of residents in each class', x = 'Degree of influence', title = 'Figure1 Degree of infl householders have on management by Type and No of Residents') + facet_wrap(~Type)

## 2. Second plot

# place code for vis here

dat2<-housing %>% group_by(Sat,Infl,Type) %>% summarise(Frequency = sum(Freq))

ggplot(data = dat2, aes(x = Sat, y = Frequency, fill = Infl))+
  
  geom_bar(stat = "identity", position = "dodge")+
  
  facet_wrap(~Type)+
  
  labs(x="Satisfaction", y="Count",title= 'Figure 2 Influence of Satisfaction on Accomodation Type' )+
  
  scale_fill_discrete(name="Influence")

## 3. Third plot

# place code for vis here
ggplot(data = housing,aes(x =Sat, y = Freq, fill = Cont))+
  
  geom_bar(stat = "identity", position = "dodge")+
  
  facet_wrap(~Cont)+ 
  
  labs(x="Satisfaction", y="Count", title='Figure 3 Relationship between Contact and Satisfaction')+
  
  scale_fill_discrete(name="Contact")

## 4. Fourth plot

# place code for vis here
ggplot(housing, aes(x=Type, y=Freq)) + geom_point(aes(color = Infl)) + geom_point(shape=21)+facet_grid(Infl~.) + labs(y = 'The numbers of residents in each class', x = 'Type of rental accomodation', title = 'Figure 4:Type of Accomodation by Influence and No. of Residents') 

5. Fifth plot

# place code for vis here
ggplot(housing, aes(Freq, Sat)) +
  geom_point(aes(size = Freq, color = Freq)) +
  facet_grid(Type ~ .) +
  guides(
    size = guide_legend(title = '# of Residents'),
    color = guide_legend(title = '# of Residents')
  ) +
  labs(x = '# of Residents',
       y = 'Satisfaction Level',
       title = 'Figure5 Satisfaction Level by Rental Type')