#select(CITY_DECODE, DESIGN_STYLE_DECODE) %>% selects the columns “CITY_DECODE” and “DESIGN_STYLE_DECODE”
#drop_na(c(CITY_DECODE, DESIGN_STYLE_DECODE)) %>% drop the data of CITY_DECODE and DESIGN_STYLE_DECODE which has NA inside
#filter(DESIGN_STYLE_DECODE==“Townhouse”) %>% filter the data in DESIGN_STYLE_DECODE and only data with “townhouse” will be left on the column “DESIGN_STYLE_CODE”.
#group_by(CITY_DECODE) %>% Group the data in column “CITY_DECODE” depending on what groups are inside the column
#summarize(count=n()) %>% it shows the column of CITY_DECODE and its count
#filter(count>1000) %>% filter the data of CITY_DECODE with count greater than 1000
#mutate(prop= count/sum(count)) creates another column where it shows the proportion of CITY_DECODE with count greater than 1000 by using the formula count/sum(count)

starwars %>% 
  select(name, hair_color,sex) %>% 
  drop_na(hair_color, sex) %>% 
  filter( hair_color %in% c("brown","black")) %>% 
  ggplot(aes(hair_color)) +
  geom_bar(aes(fill=sex),position = position_dodge(), color="black") +
  scale_y_continuous(expand=c(0,0), limits = c(0,12)) +
  labs(x="Hair Color", y="Count") +
  theme_classic()

It is evident that there are more male characters compared to female in general. With respect to hair color, a lot of male and female characters have brown hair color compared to black.

starwars %>% 
  drop_na(eye_color, mass, sex) %>% 
  select(name, mass,eye_color, sex) %>% 
  group_by(eye_color, sex) %>% 
  filter(sex %in% c("male","female")) %>% 
  filter(eye_color %in% c("black","brown","blue","yellow")) %>% 
  summarize(mean=round(mean(mass),1)) %>% 
  ggplot(aes(x=reorder(eye_color,-mean), y=mean, fill=sex)) +
  geom_bar(position = position_dodge(), stat="identity", color="black") +
  geom_text(aes(label=mean),position = position_dodge(0.9),vjust=-0.4, width=0.5) +
  labs(x="Eye Color", y="Average Mass (in kg)") +
  scale_y_continuous(expand=c(0,0), limits=c(0,110)) +
  theme_classic()
## `summarise()` has grouped output by 'eye_color'. You can override using the
## `.groups` argument.
## Warning in geom_text(aes(label = mean), position = position_dodge(0.9), :
## Ignoring unknown parameters: `width`

In general, male characters has greater average mass (in kg) for every eye color compared to female characters but the one with the heaviest average mass for male characters are the ones with the blue eye color followed by brown, blue, and yellow. In female characters, the one with the heaviest average mass (in kg) are the ones with blue eye color followed by black, yellow, and brown.