Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Scatterplots.md #214

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Presentation/Figures/Scatterplots.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,41 @@ This results in:
![seaborn_scatterplot](Images/Scatterplots/seaborn_scatter.png)


Alternatively, you can also use the seaborn.objects library which is more built around the grammar of graphics, by layering objects.
```python
import seaborn.objects as so
from seaborn import load_dataset

# Load the tips dataset
df = load_dataset("tips")

"""
Below we'll make a simple scatter plot with a linear trendline fit to the
scatter using seaborn.objects

Comments are provided on each line to help call out what each line is doing
"""

# Initialize the plot instance
plot = (so.Plot(data=df, x='total_bill', y='tip', color='time') #General aesthetic variables
.add(so.Dots(pointsize=5)) # Layer dots (scatter) aesthetic with size 5 for the dots
.add(so.Line(), so.PolyFit(order=1)) # Layer a trendline with order 1 (linear)
.label(title='Total Bill Due vs Tip Amount (by Time)', # Manually set the labels
x='Total Bill Due (in dollars)',
y='Tip Amount (in dollars)',
color='Time')
.theme({"axes.facecolor": "w"}) # Remove spines and make the entire chart area white
)


plot.plot() #Call the plot
```
This results in:

![seaborn_objects_dotplot](Images/Scatterplots/seaborn_objects_scatter.png)



## R
In R, one of the best tools for creating scatterplots is the function `ggplot()`, found in the `ggplot2` package. For this demonstration, we will also be using a dataset already built in to R called `mtcars`.

Expand Down
Loading