geom_linerange()
geom_pointrange()
geom_errorbar()
geom_crossbar()
geom_ribbon()
You can flip opientation of these geometries simply by flipping their positional aesthetics mapping.
Note: when flipping aesthetics, in certain cases, you will have to also change the position adjustment of the geometry.
For example, when flipping orientation from vertical to horizontal, position_dodge()
should be replaced with position_dodgev()
(i.e. "vertical dodge").
import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/ToothGrowth.csv")
err_df = df.groupby(by=['supp', 'dose']).agg({'len': ['min', 'max', 'median']}).reset_index()
err_df.columns = ['supp','dose', 'len_min', 'len_max', 'length']
err_df
supp | dose | len_min | len_max | length | |
---|---|---|---|---|---|
0 | OJ | 0.5 | 8.2 | 21.5 | 12.25 |
1 | OJ | 1.0 | 14.5 | 27.3 | 23.45 |
2 | OJ | 2.0 | 22.4 | 30.9 | 25.95 |
3 | VC | 0.5 | 4.2 | 11.5 | 7.15 |
4 | VC | 1.0 | 13.6 | 22.5 | 16.50 |
5 | VC | 2.0 | 18.5 | 33.9 | 25.95 |
errorbar_v = geom_errorbar(aes(x='dose', ymin='len_min', ymax='len_max'), position=position_dodge(0.95))
errorbar_h = geom_errorbar(aes(y='dose', xmin='len_min', xmax='len_max'), position=position_dodgev(0.95))
gggrid([
ggplot(err_df, aes(color='supp')) + errorbar_v + ggtitle("Vertical"),
ggplot(err_df, aes(color='supp')) + errorbar_h + ggtitle("Horizontal")
])
p = ggplot(err_df, aes(y='dose', x='length', xmin='len_min', xmax='len_max', color='supp')) +\
xlab("Tooth length [mm]")
gggrid([
p + geom_crossbar(position=position_dodgev(0.95)) + ggtitle('geom_crossbar()'),
p + geom_pointrange(position=position_dodgev(0.95)) + ggtitle('geom_pointrange()'),
p + geom_linerange(position=position_dodgev(0.95)) + ggtitle('geom_linerange()'),
p + geom_ribbon() + ggtitle('geom_ribbon()')
], ncol=2, vspace=20.0)