a. Create a barplot of the number of starwars characters with either
brown or black hair color. Color each bar based on the sex of the
character. Make sure to remove NAs in the data before creating the plot.
Also, provide the appropriate labels of the axes. Describe the
plot.
starwars %>%
select(hair_color, sex) %>%
filter(hair_color %in% c("brown", "black")) %>%
drop_na(c(hair_color,sex)) %>%
group_by(sex, hair_color) %>%
summarize(count = n()) %>%
ggplot(aes(x = hair_color, y = count, fill = sex)) +
geom_bar(position=position_dodge(), stat="identity")+
geom_text(aes(label = count), vjust = -0.3, color="black",
position=position_dodge(0.9), size=3.0)+
scale_y_continuous(expand=c(0,0), limits=c(0,12))+
labs(x="Hair Color", y="Number of Starwars Character")+
theme_classic()
## `summarise()` has grouped output by 'sex'. You can override using the `.groups`
## argument.

## The table shows that both black and brown hair color are famous among the male starwars characters. The brown hair color is dominant among the male than the female starwars characters. For the black hair color there are 9 males and 3 females, and forthe brown hair color there are 11 males and 6 females.
b. Create a barplot of the means of the mass of each starwars
character categorized according to their eye color and sex. Indicate the
means on top of each bar. Make sure to remove NAs in the data before
creating the plot. Also, provide the appropriate labels of the axes.
Describe the plot
starwars %>%
select(eye_color, sex, mass) %>%
filter(sex %in% c("male", "female")) %>%
filter(eye_color %in% c("black", "brown", "blue","yellow")) %>%
drop_na(c(eye_color, sex, mass)) %>%
group_by(eye_color, sex) %>%
summarize(m = mean(mass)) %>%
ggplot(aes(x = eye_color, y = m , fill = sex), bins=50,) +
geom_bar(position=position_dodge(), stat="identity")+
geom_text(aes(label=sprintf("%0.1f", round(m, digits= 1))), vjust = -0.3,
color="black", position=position_dodge(0.9), size=3.0,)+
labs(x="Eye Color", y="Average Mass of Starwars Characters")+
theme_classic()+
scale_y_continuous(expand=c(0,0), limits=c(0,110))
## `summarise()` has grouped output by 'eye_color'. You can override using the
## `.groups` argument.

# The table shows the Eye color of the Starwars characters in accordance to their average mass. Both for male and female, the greatest average mass are those who has blue eye color, while the least average mass are those who has brown eye color.In every kind of eye color, males surpasses females in line with the average mass.