Penguin Body Condition (Functions)
Body condition describes the mass of an animal relative to the mass expected given its size. Individuals that are heavier than expected are considered to be in better condition.
If the file penguins.csv is not in your working directory then download it.
-
Write a function called
est_mass_from_flipperthat takesflipper_length(in mm),a, andbas arguments. Set default arguments fora = 0.018andb = 2.33. The function should estimate the expected body mass usingmass = a * flipper_length ^ b. Use the function to estimate the expected mass of a penguin with a flipper length of 200 mm. -
Write a function called
calc_body_conditionthat takesobserved_massandexpected_massas arguments and returns the body condition, where body condition isobserved_mass / expected_mass. Use the function to calculate the body condition of a penguin that weighs 4200 g but was expected to weigh 4000 g. -
Load
penguins.csvusingread_csv(). Usemutate()and the two functions you wrote to add a new column namedbody_conditionto the data frame. -
Calculate the average
body_conditionfor eachsexof eachspecies. -
Make an unstacked histogram of body condition with the bars colored by island with one subplot (facet) for each year.