Skip to content

Commit

Permalink
Merge pull request #214 from RommelArtola/patch-1
Browse files Browse the repository at this point in the history
Update Scatterplots.md
  • Loading branch information
NickCH-K authored Aug 15, 2024
2 parents a06040a + e451194 commit 5f7bbb7
Showing 1 changed file with 35 additions and 0 deletions.
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

0 comments on commit 5f7bbb7

Please sign in to comment.