csci297b Exercise 5 ggplot2 (Solution)

$ 29.99
Category:

Description

2. Open a new R script in the project called exercise05
3. Load the penguins dataset and answer the following questions in your script.
4. How many rows are in penguins? How many columns?
5. What does the bill_depth_mm variable in the penguins data frame describe? Read the help for ?penguins to find out.
6. Make a scatterplot of bill_depth_mm vs. bill_length_mm. That is, make a scatterplot with bill_depth_mm on the y-axis and bill_length_mm on the x-axis. Describe the relationship between these two variables.
7. What happens if you make a scatterplot of species vs. bill_depth_mm? What might be a better choice of geom?
8. Why does the following give an error?
ggplot(data = penguins) + geom_point()
Fix it in your R script.
9. What does the na.rm argument do in geom_point()? What is the default value of the argument? Create a scatterplot where you successfully use this argument set to TRUE.
10. Add the following caption to the plot you made in the previous exercise: “Data come from the palmerpenguins package.” Hint: Take a look at the documentation for labs().
11. Recreate the following visualization. What aesthetic should bill_depth_mm be mapped to? And should it be mapped at the global level or at the geom level?

12. Run this code in your head and predict what the output will look like. Then, run the code in R and check your predictions.
ggplot(
data = penguins, mapping = aes(x = flipper_length_mm, y = body_mass_g, color = island)
) +
geom_point() + geom_smooth(se = FALSE)
13. Will these two graphs look different? Why/why not?
ggplot(
data = penguins,
mapping = aes(x = flipper_length_mm, y = body_mass_g)
) +
geom_point() + geom_smooth()
ggplot() +
geom_point(
data = penguins, mapping = aes(x = flipper_length_mm, y = body_mass_g)
) +
geom_smooth(
data = penguins, mapping = aes(x = flipper_length_mm, y = body_mass_g)
)

Reviews

There are no reviews yet.

Be the first to review “csci297b Exercise 5 ggplot2 (Solution)”

Your email address will not be published. Required fields are marked *