Code Studio: Scatterplot with a Trend Line
Build the kind of plot Scatterplots in ggplot2 describes, and read a number off the model behind it.
The program reads an iris species: setosa, versicolor or virginica.
- Keep only the rows of
irisfor that species. - With ggplot2, draw
Petal.WidthagainstPetal.Lengthas points, add a straight trend line withgeom_smooth(method = "lm", formula = y ~ x), and title it with the species. - Fit the same line with
lm(Petal.Width ~ Petal.Length, data = ...)and print its slope rounded to 3 decimal places, asSlope: …
For which species does petal width rise fastest with length? Does the grey band around the line agree with how scattered the points look?
Run draws your plot under the output. Check and Submit test the numbers your program prints.
Build the kind of plot Scatterplots in ggplot2 describes, and read a number off the model behind it.
The program reads an iris species: setosa, versicolor or virginica.
- Keep only the rows of
irisfor that species. - With ggplot2, draw
Petal.WidthagainstPetal.Lengthas points, add a straight trend line withgeom_smooth(method = "lm", formula = y ~ x), and title it with the species. - Fit the same line with
lm(Petal.Width ~ Petal.Length, data = ...)and print its slope rounded to 3 decimal places, asSlope: …
For which species does petal width rise fastest with length? Does the grey band around the line agree with how scattered the points look?
Run draws your plot under the output. Check and Submit test the numbers your program prints.