Skip to content

Instantly share code, notes, and snippets.

@malcolmbarrett
Created May 16, 2023 16:36
Show Gist options
  • Save malcolmbarrett/6ddb75311b9e1ea4200fe5ec2dcf0ea4 to your computer and use it in GitHub Desktop.
Save malcolmbarrett/6ddb75311b9e1ea4200fe5ec2dcf0ea4 to your computer and use it in GitHub Desktop.
---
title: "Untitled"
format: html
jupyter: python3
---
```{python}
#| label: setup
#| include: false
import pandas as pd
from plotnine import ggplot, aes, geom_point, geom_smooth, scale_y_log10, scale_x_log10, theme_minimal, labs
from plotnine.data import msleep
```
```{python}
#| label: fig-sleep-total
#| fig-cap:
#| - "Sleep total versus body weight"
#| - "Sleep total versus brain weight"
#| layout-ncol: 2
(ggplot(msleep, aes('sleep_total', 'bodywt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Body Weight (kg)"))
(ggplot(msleep, aes('sleep_total', 'brainwt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Brain Weight (kg)"))
```
```{python}
#| label: fig-sleep-total2
#| fig-cap:
#| - "Sleep total versus body weight"
#| - "Sleep total versus brain weight"
#| layout-ncol: 2
p1 = (ggplot(msleep, aes('sleep_total', 'bodywt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Body Weight (kg)"))
p2 = (ggplot(msleep, aes('sleep_total', 'brainwt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Brain Weight (kg)"))
p1
p2
```
```{python}
#| label: fig-sleep-total3
#| fig-cap:
#| - "Sleep total versus body weight"
#| - "Sleep total versus brain weight"
#| layout-ncol: 2
p1 = (ggplot(msleep, aes('sleep_total', 'bodywt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Body Weight (kg)"))
p2 = (ggplot(msleep, aes('sleep_total', 'brainwt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Brain Weight (kg)"))
p1
p2.draw()
```
```{python}
#| label: fig-sleep-total4
#| fig-cap:
#| - "Sleep total versus body weight"
#| - "Sleep total versus brain weight"
#| layout-ncol: 2
p1 = (ggplot(msleep, aes('sleep_total', 'bodywt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Body Weight (kg)"))
p2 = (ggplot(msleep, aes('sleep_total', 'brainwt')) +
geom_point(color="#ccc") +
geom_smooth(color="#4682B4") +
scale_y_log10() +
scale_x_log10() +
theme_minimal() +
labs(x="Total Sleep (hours)", y="Brain Weight (kg)"))
p1.draw()
p2.draw()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment