Example of grouped bar chart with error bars
See original GitHub issueIt took me a frustratingly long time to figure out how to do this, so I figured I would share an example if it was wanted for the gallery/tutorials/something else. In particular, dealing with the facet strictly after layering is a bit tricky.
Example 1: Grouped Bar Chart with Error Bars (note that color is not used, because then I cannot get the error bars to show up black)
import altair as alt
from vega_datasets import data
source = data.barley()
bars = alt.Chart().mark_bar().encode(
x='year:O',
y='mean(yield):Q',
#color='year:N',
)
error_bars = bars.mark_rule().encode(
x='year:O',
y='ci0(yield):Q',
y2='ci1(yield):Q'
)
alt.layer(bars, error_bars, data=source).facet(
column='site:N'
)
Example 2: Grouped Plot with Error Bars (color can now be used easily)
import altair as alt
from vega_datasets import data
source = data.barley()
points = alt.Chart().mark_point(filled=True, size=50).encode(
x='year:O',
y=alt.Y('mean(yield):Q', title='Mean Yield'),
color='year:N',
)
error_bars = bars.mark_rule().encode(
x='year:O',
y='ci0(yield):Q',
y2='ci1(yield):Q'
)
alt.layer(points, error_bars, data=source).facet(
column='site:N'
)
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Grouped barplot in R with error bars - Stack Overflow
The problem is that I need to do this for 50 genes, and 4 species, so my script is gonna get super super...
Read more >Grouped barplot in R with error bars - GeeksforGeeks
In this article, we are going to see how to create grouped barplot in the R programming language with error bars.
Read more >grouped barplot with error bars - RStudio Community
Hi, I'm new to R and I'm trying to plot a grouped bar plot with se bars, but so far no success. I'd...
Read more >Adding error bars to a grouped bar plot - MATLAB Answers
Hi! I'm trying to plot a grouped bar graph with standard errors, and have managed this so far, which almost works but the...
Read more >Barplot with error bars - The R Graph Gallery
This post describes how to add error bars on your barplot using R. Both ggplot2 and base R solutions are considered. A focus...
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 FreeTop 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
Top GitHub Comments
How can error bars be made to show on a grouped stacked bar chart using already calculated standard deviation values? I create the grouped stacked bar chart using Grant Langseth’s answer to this question. In my dataset, the standard deviation of each data point (appearing in a given stacked bar) is already determined and stored in another column. Thanks!
Hi @tigercosmos, I was not able to do this. I eventually had to change the chart type.