facet_wrap()¶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/mpg2.csv')
df.head(3)
p = (
ggplot(df,
aes('engine horsepower', 'miles per gallon',
color=as_discrete('origin of car',order=-1)))
+ geom_point()
+ theme_grey() + ggtitle('Efficiency vs Engine Horsepower')
)
p
For example, there are no 3-cylinder engine cars originated in the US. Accordingly, this facet panel is dropped.
p + facet_wrap(['origin of car', 'number of cylinders'], order=[-1, 1], ncol=3)
drop Parameter to Control Empty Panels¶Use drop=False to show all factor levels regardless of whether they occur in the data.
p + facet_wrap(['origin of car', 'number of cylinders'], order=[-1,1], ncol=5,
drop=False
)