By using the data from ?heatmap.2
:
data(mtcars)
x<-scale(mtcars)
set.seed(123)
tf<-sample(rownames(x), 5)
tf
[1] "Merc 280" "Pontiac Firebird" "Merc 450SL"
"Fiat X1-9" "Porsche 914-2"
heatmap.2(x)
what I wanted is to color row names in tf
(on the right) in red or the branches of these names (on the left) in red color (or both in red will be greater). I dug around and can't find the solutions. Does anybody have suggestions using the above sample?
In order to colour the row names in red you need to do the following:
data(mtcars)
x<-scale(mtcars)
set.seed(123)
tf<-sample(rownames(x), 5)
Create a vector cols with the colours of the row names. Red for tf and Black anywhere else
#initiate cols with all black
cols <- rep('black', nrow(mtcars))
#turn red the specified rows in tf
cols[row.names(mtcars) %in% tf] <- 'red'
Now plot using the colRow
argument:
heatmap.2(x, colRow = cols)
Output:
As for colouring the dentrogram, I don't think there is an option to do this in heatmap.2
. There seems to be a way with the Heatplus
package and function annHeatmap2
but I have no experience in using this. There is an example here if you are interested in exploring new packages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.