import pandas as pd
from lets_plot import *
from lets_plot.mapping import as_discrete
LetsPlot.setup_html()
iris_df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv")
print(iris_df.shape)
iris_df.head()
(150, 5)
sepal_length | sepal_width | petal_length | petal_width | species | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
1 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
2 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
3 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
4 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
mpg_df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")
print(mpg_df.shape)
mpg_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 |
ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges()
min_height
parameter¶df = pd.DataFrame({
"x": [1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7],
"y": [-.4, -.4, -.4, -.4, -.4, -.4, -.4, -.8, -.8, -.8, -.8, -.8, -.8, -.8],
"h": [.4, -.2, .6, -.8, .3, .1, .7, .1, .3, .1, -.6, -.1, -.3, -.1],
})
ggplot(df) + \
geom_area_ridges(aes("x", "y", height="h"), stat='identity', color="black", fill="#3182bd", min_height=-.4)
trim
and tails_cutoff
parameters¶width, height = 400, 300
bunch = GGBunch()
bunch.add_plot(ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges(trim=False, tails_cutoff=None) + \
ggtitle("Default: trim=False, tails_cutoff=None"),
0, 0, width, height)
bunch.add_plot(ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges(trim=False, tails_cutoff=0) + \
ggtitle("trim=False, tails_cutoff=0"),
width, 0, width, height)
bunch.add_plot(ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges(trim=False, tails_cutoff=3) + \
ggtitle("trim=False, tails_cutoff=3"),
0, height, width, height)
bunch.add_plot(ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges(trim=True) + \
ggtitle("trim=True"),
width, height, width, height)
bunch.show()
scale
parameter¶ggplot(iris_df, aes("sepal_length", "species")) + \
geom_area_ridges(scale=1.5)