Facetted grouped boxplot
See original GitHub issueIn the seaborn
plotting library exists catplot() that allows facetted grouped boxplots:
import pandas as pd
## the following code needs the "xlrd" library installed for reading Excel files.
## alternatively, you can use the attached data.csv which contains the same data using:
# dataProp = pd.read_csv('https://github.com/altair-viz/altair/files/4565572/data.zip')
link = 'https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/812408/Gas_and_Electric_Consumption_Multiple_Attributes_Table_2019.xlsx'
data = pd.read_excel(link,'2017 Consumption')
dataGas = data.loc[data['Gas present']=='Yes',]
dataProp = dataGas.loc[dataGas['Electricity type']=='Standard',]
import seaborn as sns
sns.catplot(x='Number of bedrooms',
y='Median - Gas',
col='Region',
hue='Property age',
kind="box",
data=dataProp,
col_wrap=4,
hue_order=['Pre 1919','1919-44','1945-64','1965-1982','1983-92','1993-99'])
I tried to replicate this using altair
, but the boxplots get stacked on themselfs:
import altair as alt
alt.Chart(dataProp).mark_boxplot().encode(
x='Number of bedrooms:O',
y='Median - Gas',
color=alt.Color('Property age:O',
sort=['Pre 1919','1919-44','1945-64','1965-1982','1983-92','1993-99']),
facet=alt.Facet('Region:N',
columns=4),
).interactive()
I tried to combine facet=...
and column=...
parameters in encode()
and tried my hands on the repeat()
method without success. Is there a way to show the grouped boxplots next to each other like in seaborn
’s catplot()
?
Thank you for you help.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:7 (1 by maintainers)
Top Results From Across the Web
R ggplot: grouped boxplot using group-variable in facet
Create two seperate graphs and combine them with a shared legend. Create two different y-axes in one graph; Use facet grid. Since 1....
Read more >Grid of clustered/grouped boxplots - bioST@TS
In this tutorial, we will see how to make a grid of clustered/grouped boxplots using facet_wrap() and facet_grid() . Such a grid may...
Read more >ggplot2 facet : split a plot into a matrix of panels - Easy Guides
The facet approach partitions a plot into a matrix of panels. Each panel shows a different subset of the data. This R tutorial...
Read more >Grouped boxplot with ggplot2 - The R Graph Gallery
A grouped boxplot is a boxplot where categories are organized in groups and subgroups. Here we visualize the distribution of 7 groups (called...
Read more >Chapter 5 Using ggplot2 | Data Science with R - GitHub Pages
Produce scatter plots, boxplots, and time series plots using the ggplot2 package ... First we need to group the data and count records...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, there’s no way to do this yet in Altair/Vega-Lite (the way to make grouped boxplots is to use facet, and vega-lite does not support facets of facets).
A future vega-lite release will hopefully include an offset encoding which will make this type of chart possible.
@VietTralala Sorry I should have mentioned that this has been added in the development version on GitHub, but it has not yet been released. As you noticed, you can install directly from GitHub to get access to the X/YOffset encodings. I am not sure why it is not working for you, but you should not have to do anything special with the import, so try importing as usual
import altair as alt
. It is important that you close down all notebooks (or clear their output) and the reopen jupyterlab. If there is a plot open that has been created by an with an old version of vegalite, that can create issues.