How to turn a colored histogram into a stacked bar chart?

apoloduvalis
apoloduvalis New Altair Community Member
edited November 5 in Community Q&A
I want to create a visualization from data with columns SEXO (sex, with 1 for male and 2 for female) and INGLABO (income, which is a range of four bins) with 24,984 examples. My goal is to show a column for male and other for female, where each segment of the bar be the count of examples of that sex within the appropriate income range.
My first choice was an histogram, with value column as SEXO (1,2) and color as INGLABO (the ranges are in the legend at the bottom of the chart). Despite there should be displayed 13,545 records for male (1) and 11,439 for female (2) in two single columns, each color (counts of values for a income range of a particular sex) is shown as a separated column, so you only get to see the more frequent group instead of visualizing each group of a same sex stacked upon each other. 

Is this a bug? Or am I doing something wrong? The histogram seems to work fine without color.

I got closer to the visualization I need with a TurboPrep "Histogram color" Chart, but it downsized the sample from 24,984 records to 5,000, so it's kind of useless:

Any ideas? Thanks in advance,
Andrés

Best Answer

Answers

  • sgenzer
    sgenzer
    Altair Employee
    hi @apoloduvalis I'm sorry no one has chimed in here. Can you post some data so I can try to see how a chart would look?
  • apoloduvalis
    apoloduvalis New Altair Community Member
    edited March 2019
    Hi @sgenzer , thank you for showing up!
    The colored histogram I am getting shows the different segments in a different color, but one behind the others instead of stacking them one upon each other. When I hover the pointer over the legend of the last segment (0, the black one) as if I was going to hide it, I can see the other segments behind it because they turned semi-transparent. I would like to attach an image but since I am still a newbie the system does not allow me to do it.

    I started to think that the histogram not stacking the different colored segments was not a bug but a feature of RM. However, I got closer to the visualization I need with a TurboPrep "Histogram color" Chart, which with the same data managed to show a histogram with stacked segments. Sadly, it downsized the sample from 24,984 records to 5,000 (perhaps a limitation of the free version?), so it has not enough samples to include data for the red color (0) or to get the right proportions of the distribution.

    I have attached the data I am using as source for the histogram as a .csv file. I hope you can reproduce this behavior and figure out what is going on.
    Kind regards,
    Andrés
  • apoloduvalis
    apoloduvalis New Altair Community Member
    Well, it seems my second posts upgraded me from newbie to learner so now I can attach images. My histogram looks like this:



    And the TurboPrep histogram color chart looks like this:


  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    Currently you would need to pivot the data manually first, and then use a "Column" chart with stacking. Histograms in the new visualizations are not stacking the data on purpose, as they work on numerical data, and usually the bins between different colors do not have anywhere close to a 100% match.
    We will have a "Color Group" option coming for Line/Bar/Column/Area charts coming at some point in the future, where you can basically split the data into different groups (per category value), and at that point you can very easily do what you are currently trying to achieve.

    Turbo Prep still uses the old charts, which is why it's a bit different story there.

    Regards,
    Marco