How to color-code columns in MATLAB Clustergram?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to label specific columns in a MATLAB clustergram with particular colors to indicate similarities between columns but not necessarily within dendogram clusters (I already have the clustergram made, just trying to better explain my data). I am aware of the ColumnGroupMarker function, but I do not want them based on cluster - I'd like to be able to control whether columns in the same group have different colors, similar to this academic paper has the bars for liver/lung and metastatic/normal:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1035850/image.png)
0 commentaires
Réponses (1)
Naren
le 26 Oct 2023
Hello Steven,
To label specific columns in a MATLAB clustergram with colors, you can use the `ColumnGroupMarker` function to achieve this effect. However, as you mentioned, you don't want to group columns based on the dendrogram clusters, but rather you want to control the colouring of individual columns or groups of columns based on your criteria.
One way to achieve this is by creating a custom color map and using the `ColumnGroupMarker` function to assign colors to specific columns or column groups.
Here's a step-by-step guide on how to do this:
1. Create a custom colormap that defines the colors you want to use for column labeling. You can use the `colormap` function to create your colormap. For example:
customColormap = [1 0 0; 0 1 0; 0 0 1; 1 1 0]; % Define your own RGB colors
colormap(customColormap);
In this example, we have defined a colormap with four different colors.
2. Create a vector that assigns a color to each column or group of columns. You can use a numeric vector to indicate which color each column should be assigned. For example:
colorAssignment = [1 2 3 4]; % Assign colors to columns based on your criteria
Here, we are assigning the first column to color 1, the second column to color 2, and so on.
3. Use the `ColumnGroupMarker` function to apply the custom colors to the clustergram. You can pass the colorAssignment vector as an argument to this function:
clustergram(data, 'Colormap', customColormap, 'ColumnGroupMarker', colorAssignment);
This will apply the custom colors to the columns based on your colorAssignment vector.
4. Customize the color labels as needed. You can use the `ColorMap` property to customize the color labels, and you may also want to adjust the legend or color bar to provide a key for the colors you've used.
This approach allows you to control the coloring of specific columns or groups of columns in a clustergram based on your criteria, rather than relying on the default dendrogram clustering. Adjust the `customColormap` and `colorAssignment` vectors to match your specific requirements.
Regards, Naren
0 commentaires
Voir également
Catégories
En savoir plus sur Expression Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!