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()
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)
p = ggplot(df, aes("hwy", "drv", fill="drv"))
p1 = p + geom_area_ridges(quantile_lines=True) + \
ggtitle("geom_area_ridges(): quantiles=[.25, .5, .75] (default)")
p2 = p + geom_area_ridges(quantile_lines=True, quantiles=quantiles) + \
ggtitle("geom_area_ridges(): quantiles={0}".format(quantiles))
gggrid([p1, p2])
p = ggplot(df, aes("drv", "hwy", fill="drv"))
p1 = p + geom_violin(quantile_lines=True) + \
ggtitle("geom_violin(): quantiles=[.25, .5, .75] (default)")
p2 = p + geom_violin(quantile_lines=True, quantiles=quantiles) + \
ggtitle("geom_violin(): quantiles={0}".format(quantiles))
gggrid([p1, p2])
..quantile.. in Aesthetics Mapping¶common_args = {'color': "black", 'alpha': .95}
quantiles = np.linspace(0, 1, 15)
fill_diverging = scale_fill_gradient2(low="white", mid="#3F8F77", high="white", midpoint=0.5)
p = ggplot(df, aes("hwy", group="drv"))
p1 = p + geom_density(**common_args) + \
ggtitle("geom_density(): fill=None in aes (default)")
p2 = p + geom_density(aes(fill='..quantile..'), quantiles=quantiles, **common_args) + fill_diverging + \
ggtitle("geom_density(): fill='..quantile..' in aes")
gggrid([p1, p2], ncol=1) + ggsize(700, 500)
p = ggplot(df, aes("hwy", "drv"))
p1 = p + geom_area_ridges() + \
ggtitle("geom_area_ridges(): fill=None in aes (default)")
p2 = p + geom_area_ridges(aes(fill='..quantile..')) + \
ggtitle("geom_area_ridges(): fill='..quantile..' in aes")
gggrid([p1, p2])
p = ggplot(df, aes("drv", "hwy"))
p1 = p + geom_violin() + \
ggtitle("geom_violin(): fill=None in aes (default)")
p2 = p + geom_violin(aes(fill='..quantile..')) + \
ggtitle("geom_violin(): fill='..quantile..' in aes")
gggrid([p1, p2])