Search code examples
rheatmapaxis-labels

Changing heatmap ticks from numbers to months in R


I have heatmap with month number on the y-axis. I want to change the numbers to month name (e.g., "Jan.","Feb.","Mar.","Apr."). Here is the heatmap

enter image description here

and this is my code:

heatmap(data, Rowv=NA, Colv=NA, margins=c(3,3),
                   col = magma(50), scale="none", xlab = "Hours",
                   ylab = "Month")

Solution

  • The values printed on the axes are determined by the row and column names of the object you pass in. There is a built in vector of month abbreviations that you can use. Try

    rownames(data) <- month.abb
    

    Or you could set the values to whatever you like.