import pandas as pd
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
print(df.shape)
df.head()
(234, 12)
Unnamed: 0 | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
1 | 2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
2 | 3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
3 | 4 | audi | a4 | 2.0 | 2008 | 4 | auto(av) | f | 21 | 30 | p | compact |
4 | 5 | audi | a4 | 2.8 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | compact |
quantile_lines
¶common_args = {'color': "black", 'alpha': .75}
p = ggplot(df, aes("hwy", fill="drv"))
p1 = p + geom_density(**common_args) + \
ggtitle("geom_density(): quantile_lines=False (default)")
p2 = p + geom_density(quantile_lines=True, **common_args) + \
ggtitle("geom_density(): quantile_lines=True")
gggrid([p1, p2], ncol=1) + ggsize(700, 500)
p = ggplot(df, aes("hwy", "drv", fill="drv"))
p1 = p + geom_area_ridges() + \
ggtitle("geom_area_ridges(): quantile_lines=False (default)")
p2 = p + geom_area_ridges(quantile_lines=True) + \
ggtitle("geom_area_ridges(): quantile_lines=True")
gggrid([p1, p2])
p = ggplot(df, aes("drv", "hwy", fill="drv"))
p1 = p + geom_violin() + \
ggtitle("geom_violin(): quantile_lines=False (default)")
p2 = p + geom_violin(quantile_lines=True) + \
ggtitle("geom_violin(): quantile_lines=True")
gggrid([p1, p2])
quantiles
¶quantiles = [0, .02, .3, .7, .98, 1]
common_args = {'color': "black", 'alpha': .75, 'quantile_lines': True}
p = ggplot(df, aes("hwy", fill="drv"))
p1 = p + geom_density(**common_args) + \
ggtitle("geom_density(): quantiles=[.25, .5, .75] (default)")
p2 = p + geom_density(quantiles=quantiles, **common_args) + \
ggtitle("geom_density(): quantiles={0}".format(quantiles))
gggrid([p1, p2], ncol=1) + ggsize(700, 500)