Contents

Related

Python grammar of graphics

import pandas as pd

mpg = pd.read_csv("./data/mpg.csv")

mpg.head()

mpgcylindersdisplacementhorsepowerweightaccelerationmodel_yearoriginname
018.08307.0130350412.0701chevrolet chevelle malibu
115.08350.0165369311.5701buick skylark 320
218.08318.0150343611.0701plymouth satellite
316.08304.0150343312.0701amc rebel sst
417.08302.0140344910.5701ford torino
from plotnine import *
from plotnine.data import *

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

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

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

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

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

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

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

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

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

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

<ggplot: (324562484)>