Print
Scatter Plots
Read It: Scatter Plots
Scatter plots can be used to plot two (or more) quantitative variables. Below, we will first demonstrate how to create a basic scatter plot. Then, we will show how to add a third categorical or quantitative variable to that plot.
Watch It: Video - Basic Scatter Plots (4:40 minutes)
Watch It: Video - Scatter Plots with Three Variables (6:04 minutes)
Try It: Apply Your Coding Skills in Google Colab
- Click the Google Colab file used in the video is linked here.
- Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
- Once you have it saved in your Drive, use the partial code below to create scatter plots using plotnine/ggplot.
Note: You must be logged into your PSU Google Workspace in order to access the file.
from plotnine import * # import the library # fill in the blank (...) to plot a scatter plot with 'MaxGas' on the x-axis and 'TotalGas' on the y-axis ggplot(marc) + ... # fill in the blank (...) to add a best fit line to your scatter plot from above ggplot(marc) + ... + stat_smooth(...) # fill in the blank (...) to add a third variable, 'PerfIntervalLength', to your plot ggplot(marc) + ... + stat_smooth(...)
Once you have implemented this code on your own, come back to this page to test your knowledge.