Single stacked bar

Hello all, I searched the forum up and down but could not find the answer to my question. Sorry, if this is really noob question but I need some help.

I have a table with values:

list, gender
a, men
b, men
c, women
d, women
e, men
f, women
g, women

I loaded it to KNIME, and trying to create a --single-- stacked bar with the x label “list” and the y label attendees with the stacked bar.

So I created a bar chart, category column is set to “gender” and aggregation method “occurrence”. However, even if I enable the stacked bar option, it still shows the bars as:

3       4
-       -
        #
#       #
#       #
#       # 
---------------
men    women

Can any of you help pls?

Can you draw the bar chart you would like to have from this data?

My understanding is that you want a bar chart that on x axis it shows all the combination of ‘list’ and ‘gender’. For each combination you want to see how many occurrences are there using the height of the bin. Given that there would be too many bins you would like to stack them for each gender.

The Bar Chart node is only able to get one categorial feature.
If you select ‘gender’, which is made of only two categorial values (‘male’ and ‘gender’), you will always have 2 bins. The stacked option is then only available using the ‘mean’ or ’ sum’ operation.

Maybe you could use before the bar chart a pivoting node.
Select ‘Gender’ for the group columns and ‘list’ for the pivoting columns.
Aggregation methon you use ‘Count’. Set “Keep Orginal Names” in the checkbox under the aggregation method so that the column names stay clean/

The table should then look like this with only two rows and one column for the gender and more columns for each unique list category.

RowID Gender a b c d e f g
Row0 Male 0 3 4 2 0 4 3
Row1 Female 2 5 2 0 6 8 9

Then you apply the bar chart where:

  • you still use the ‘Gender’ for the category column
  • you select ‘average’ or ‘sum’. This does not matter as you are summing/averaging on a list of one item only and that does nothing.
  • you select in the twin list all the numerical columns from the table above (a,b,c,d,e,f,…)

By the way this approach also works with new bar chart node (still in labs).

There you can select ‘none’ aggregation method, so it should be less confusing to visualize numbers you prepare with a pivoting or groupby node.

Hi @paolotamag thanks for the explanation, I am new to KNIME and will try to figure out your suggestions this afternoon.

What I was trying to achieve with my data is that if I specify “occurrence” on the above-mentioned dataset, it will collate and count the occurrence of the terms. Furthermore, if I specify that I want to have a stacked graph, it will add them together into a single graph, so instead of this:

image

I will get something like this…:

image

Hi there,
ok I thought that a,b,c,… was data you wanted to visualize, not simply rowids.
I misunderstood. Now that you made a drawing is much clearer.
Take a look here at the solution I shared for you:

@DanielBog is there an approach with less nodes to visualize the same (starting with the same example table)?

Thanks
Paolo

1 Like

Thanks @paolotamag for this, it works. You do some serious magic there with the RowIDs, certainly a lesson for me thanks again!

1 Like

May I have an additional question, as this Group By element is not very clear for me.

I have another table, with the elements

A | B | C 
------------
true | false | false
false | true | false
true | true | true

If I add another rowid to it, and try to count the sum of trues in the row, it somehow does not work. For some reason I cannot count only trues in multiple rows, following your suggestion.

I would like to have the results:

A | 2
B | 2
C | 1

Sorry for the stupid question, trying to understand the logic of KNIME.

Hello,

You can use Value Counter instead of first three nodes. Or add 2 constant columns (string “People” for grouping, int x for count aggregation) followed by Pivoting node. Possibly if there are already such columns one can skip adding them and only use Pivoting node to get desired format for stacked Bar Chart.

Still bar in view is a bit too wide. Don’t know if there is option to make it more appealing.

Br,
Ivan

Hi @ipazin,
Do you mind sharing a workflow to show this other appraoch?

Still bar in view is a bit too wide. Don’t know if there is option to make it more appealing.

Currently you can do this only by placing it in a component and adjust the layout.
If you need a static image the svg creation should let you pick the image ratio in pixels.

Hello @paolotamag,

here it is:
Occurences_Stacked_Bar_Chart.knwf (55.6 KB)

Br,
Ivan

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.