Python grammar of graphics

import pandas as pd
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

mpg = pd.read_csv("data/mpg.csv")
mpg.head()
mpg cylinders displacement horsepower weight acceleration model_year origin name
0 18.0 8 307.0 130 3504 12.0 70 1 chevrolet chevelle malibu
1 15.0 8 350.0 165 3693 11.5 70 1 buick skylark 320
2 18.0 8 318.0 150 3436 11.0 70 1 plymouth satellite
3 16.0 8 304.0 150 3433 12.0 70 1 amc rebel sst
4 17.0 8 302.0 140 3449 10.5 70 1 ford torino
from plotnine import *
from plotnine.data import *

ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy")) + theme_classic()

png

<ggplot: (366319782)>
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy", color="class")) + theme_classic()

png

<ggplot: (366405940)>
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy", size="class")) + theme_classic()

png

<ggplot: (366362040)>
# Left
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy", alpha="manufacturer")) + theme_classic()

png

<ggplot: (366298329)>
# Right
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy", shape="manufacturer")) + theme_classic()

png

<ggplot: (381115233)>
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy"), color="blue") + theme_classic()

png

<ggplot: (381154256)>
ggplot(data=mpg) +\
geom_smooth(mapping=aes(x="displ", y="hwy")) + theme_classic()

png

<ggplot: (381119507)>
ggplot(data=mpg) +\
geom_smooth(mapping=aes(x="displ", y="hwy", linetype="drv")) + theme_classic()

png

<ggplot: (381071879)>
ggplot(data=mpg) +\
geom_point(mapping=aes(x="displ", y="hwy")) +\
geom_smooth(mapping=aes(x="displ", y="hwy")) + theme_classic()

png

<ggplot: (366461585)>
ggplot(data=mpg, mapping=aes(x="displ", y="hwy")) +\
geom_point(mapping=aes(color="class")) +\
geom_smooth() + theme_classic()

png

<ggplot: (366351376)>