Create heatmap from table, error "'XVariable' value must reference a single variable in the source table."

Hello,
I have a problem when trying to create a heatmap from this table
I want the y axis to display the IDs and the x axis to display the 6 different Snacks, the table is about the Liking mean_rating of the IDs for the snacks (nevermind the phases column).
When I try to create a heatmap with
heatmap(data_mean_liking, data_mean_liking.Snack, data_mean_liking.ID)
it gives me the following error: "'XVariable' value must reference a single variable in the source table."
I don't really understand the error message or how to display the heatmap I want.
Thanks for the help!
Edit: I have included part of the table for trying out.

Answers (1)

The x,y variables for a table are given as the names of the wanted columns; the dot notation returns the data.
heatmap(data_mean_liking, 'Snack', 'ID')

7 Comments

Thank you!
I tried it out and added axis names and a custom colormap but it does not integrate the rating values?
figure;
heatmap(data_mean_liking, 'Snack', 'ID');
title('Liking');
xlabel('Snack');
ylabel('ID');
colormap(inferno);
It scales color to the total the number of times each pair of x and y values appears together.
That would indicate your data are pretty-much spread all over, not concentrated in any given set of IDs.
Looking at the data given, it certainly appears each ID/Snack combination exists the same number of times..whether that's a replication of one or N is unknown, but looks to to be simply that.
Ah thank you, then it seems I started with the whole wrong layout. I see that all cells are the pink corresponding to the value 1, like you explained. I actually wanted a heatmap showing the differences in rating between the values of +100 and -100, but I chose the wrong variables?
Or did I explain it incompletely, too?
Ah! You're right on the corresponding value to the color map. I didn't try to read the value from it. On to the real problem--
You don't seem to have a "level of approval" categorical or range variable in the above data--there is the 'Rating_Mean' variable but it seems to be a calculated value that also as is would likely just be one value per cell.
It looks like maybe need to discretize it over whatever range it runs into some 4-5 levels and then use that new categorical(?) variable instead.
Yes, the Rating_Mean is a calculated variable, composed of 4 rating phases. I calculated the mean so I could create a visual overview of how people's rating for each snack differs.
But if I used a categorical variable or discretise it wouldn't I loose accuracy of the ratings?
I am not sure how I can visualise what I need. I understand why I get all the same colour for the heatmap now because, like you explained, it cross-checks the IDs with each snack, which of course is 1 each time. I thought I could somehow integrate the raitng variable, too?
The issue is that the heatmap function will count every element as different even if the average rating differs by only machine epsilon--it is every unique cross-comparison which almost certainly will end up also be 1:1 for each cell just as is the ID.
Are the 'phases' discrete rankings or independent trials or what?
However you try to agglomerate over levels will be some loss of individual precision, yes, but that's the price you'll have to pay to be able to summarize across multiple snacks/individuals to show trends instead of every separate evaluation as one observation.
I don't see a way around that.
There are four discrete phases and in each phase participants can rate a snack between on a continuous scale of (I think) -100 and +100.
Ok, thank you for your help so far! I will check on how to work with this then.

Sign in to comment.

Categories

Asked:

on 21 Feb 2021

Commented:

on 22 Feb 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!