question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example of grouped bar chart with error bars

See original GitHub issue

It 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:closed
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
bbrighttaercommented, Jan 8, 2020

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!

1reaction
bbrighttaercommented, Sep 7, 2021

Hi @tigercosmos, I was not able to do this. I eventually had to change the chart type.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found