Jump to content

Using heatmap to show % of each Y category over the entire X category


veni
Go to solution Solved by Olivier Keugue Tadaa,

Recommended Posts

Hello! I am relatively new to Spotfire and I am exploring the usage of the heatmap on a sample dataset I have that consists of: gender, agegroup, and survived ("1" = Survived, "0"= Did not survive).image.png.4261edfaf75a51a573e031901e23fef0.png

Now, I want to use the heatmap to represent the percentage of Survived="1" for each age group category as a whole of the gender category. I have added the age group and gender category into the heatmap, I am currently stuck on the aggregation portion to retrieve the percentage of those who survived in each age group with respect to their own gender category.image.thumb.png.ea45588db548f4d9369b0c6cc0a98f91.png

Would appreciate if someone would like to share their insights to me regarding this, as right now I have been trying to wrap my brain around it. Cheers!

Link to comment
Share on other sites

Thinking about it, I feel like that might be a little complicated, an alternative is where it just shows the percentage of survival based on their own categories. For example,  if I have 10 records for Female Kid, and 7 survived, so the % of survival would be 70%, which is to be represented in the heatmap for Female Kid

Link to comment
Share on other sites

Hi Veni,

When using your dataset, I get blank spaces for female kids, male teenagers and female senior citizen's.
So I assume your dataset is a bit bigger than what is posted.

Nonetheless, if I understood your first request properly, you want to present the number of survived age groups, as a percentage of the total set of data.
And your visualization needs to be a heatmap?

Kind regards,

David

Link to comment
Share on other sites

36 minutes ago, David Boot-Olazabal said:

Hi Veni,

When using your dataset, I get blank spaces for female kids, male teenagers and female senior citizen's.
So I assume your dataset is a bit bigger than what is posted.

Nonetheless, if I understood your first request properly, you want to present the number of survived age groups, as a percentage of the total set of data.
And your visualization needs to be a heatmap?

Kind regards,

David

Hi David,

Yeah that picture is just a snippet of my entire dataset of 800+ records. As for the representation, I decided that I want to present the number of those who survived within their own age group and gender. 

As for the visualization, I was just exploring the heatmap, are there other visualizations within Spotfire that you would recommend me to use?

Regards,

Veni

Link to comment
Share on other sites

Hi Veni, 

I agree with David that perhaps another visual would be more appropriate. How about a bar chart? 
Attached you'll find an example on how I approached the problem. I've created 3 calculated columns first to calculate the survival percentage per group. 

Calculated Column 1: 
//Nr Survived Per Group
Sum([Survived]) over (Intersect([Sex],[AgeGroup]))

Calculated Column 2: 
//Nr Per Group
Count(RowId()) OVER (Intersect([Sex],[AgeGroup]))

Calculated Column 3: 
//Survivor Percentage Per Group
[Nr Survived Per Group] / [Nr Per Group]

image.thumb.png.c54ee1b9b804d842183ba85f828d03f7.png


Hope this helps.

Thanks,

Alain

titanic.dxp

Link to comment
Share on other sites

13 minutes ago, Olivier Keugue Tadaa said:

Hi Veni,

You can try this expression :::: sum([Survived]) / sum([Survived]) OVER (All([Axis.Y])) since all age groups are displayed on the Y-Axis of your heat map. Ensure you change the expression if you change the settings of your heat map.
 

Here is an example attached 

Let me know if it helps

 

Heatmap example.dxp 468.63 kB · 0 downloads

I've checked out the formula you've used in the .dxp file, for some reason when I transfer it over to mine it gives this error

image.png.79b9d3e41824a807313bc5665f1e31f8.png

Link to comment
Share on other sites

11 minutes ago, Olivier Keugue Tadaa said:

If your column Survived is not an integer then you can try sum(Integer([Survived])) / sum(Integer([Survived])) OVER (All([Axis.Y])) to convert it

Hi Oliver, during the meantime I've also done the visualization using a bar chart, and it doesn't really tally up.

The way I've binned the age is as follows:

case  
when [Age]<=12 then "Kid" 
when [Age]<=18 then "Teenager" 
when [Age]<=30 then "Young Adult" 
when [Age]<=50 then "Adult"
ELSE "Senior Citizen"
end

Missing age values would be replaced with the median age.
This is what the survival rate of Female Kids should look like:

image.thumb.png.90b4109c50af9107342da0693cd00458.png

However, when I use the code you've suggested to me it gives:
image.png.58b686e17b719d49f129dc971d68fe25.png

Link to comment
Share on other sites

During the meantime, I've done some google search and someone came up with this heatmap in Python:
image.png.3bcdf00929a28684de48d2aa42ad4f14.png

Not sure if I could do this in spotfire, however

Link to comment
Share on other sites

Just now, Olivier Keugue Tadaa said:

That's normal. The row count (in the bar chart) is not the sum of survivals (in the heat map)

Oh I see, in this case would it be possible to have the percentage of its own category instead of the sum of all the survivals?

Link to comment
Share on other sites

5 minutes ago, Olivier Keugue Tadaa said:

Sure :::: sum(Integer([Survived])) / count([PassengerId]) as [%of Survived]

Thank you so much, this solved my issue.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...