#Q3
#Library used
library(tidyverse)
#Code to create a bar plot.
abalone <- read_csv("abalone.csv")
#Goal:Create a new variable called adult to
#distinguish between adult and infant abalone.
#Then, plot to visualize the relative proportions
#of adult/infant using a stacked bar plot
abalone %>%
mutate(adult = (Sex == 'M') | (Sex == 'F')) %>%
group_by(Sex) %>%
summarize(prop_adult = mean(adult)) %>%
count(Rings) %>%
ggplot(mapping = aes(x = as.factor(Rings), y = prop_adult)) +
barplot(count(Rings))
#Error
Error: object 'Sex' not found
#Dont know what is wrong
#Q4
#Goal: Create a new categorical feature called adult (non-infant) to distinguish between adult and infant abalone. Use box plots with appropriate notches to examine whether the median numbers of rings are different between adult and infant abalone.
abalone %>%
mutate(adult = (Sex == 'M') | (Sex == 'F')) %>%
group_by(Sex) %>%
summarize(prop_adult = mean(adult)) %>%
count(Rings) %>%
ggplot(mapping = aes(x = as.factor(Rings), y = prop_adult)) +
geom_boxplot(notch = TRUE)
#Error
Error: object 'Sex' not found
#Q5
#Goal: Considering only adult (non-infant) abalone, use box plots with appropriate notches to examine whether the median numbers of rings
#are different between male and female abalone
abalone %>%
mutate(adult = (Sex == 'M') | (Sex == 'F') & (Sex != 'I')) %>%
group_by(Sex) %>%
summarize(prop_adult = mean(adult)) %>%
count(Rings) %>%
ggplot(mapping = aes(x = as.factor(Rings), y = prop_adult)) +
geom_boxplot(notch = TRUE)
#Error
Error: object 'Sex' not found
#Q6
#Goal: Considering only adult abalone, use box plots with appropriate
#notches to examine whether the median proportion of an abalone’s
#weight being meat is different between male and female abalone. The proportion of an abalone’s weight being meat is
#the abalone’s meat weight divided by its entire weight
abalone %>%
mutate(female = (Sex == 'F'), male = (Sex == 'M'))) %>%
group_by(WholeWeight,ShellWeight) %>%
summarize(prop_weight_F = median(female = ShuckedWeight/WholeWeight)) %>% #No idea
count(ShuckedWeight/WholeWeight) %>%
ggplot(mapping = aes(x = as.factor(Rings), y = prop_adult)) +
geom_boxplot(notch = TRUE)