Zooming In
In the video, you saw different ways of using the coordinates layer to zoom in. In this exercise, we'll compare zooming by changing scales and by changing coordinates.
The big difference is that the scale functions change the underlying dataset, which affects calculations made by computed geoms (like histograms or smooth trend lines), whereas coordinate functions make no changes to the dataset.
A scatter plot using mtcars
with a LOESS smoothed trend line is provided. Take a look at this before updating it.
This exercise is part of the course
Intermediate Data Visualization with ggplot2
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Run the code, view the plot, then update it
ggplot(mtcars, aes(x = wt, y = hp, color = fam)) +
geom_point() +
geom_smooth()
# Add a continuous x scale from 3 to 6