2013-12-18 131 views
1

我試圖在R中創建一個熱圖,但軸標籤(它使用傳遞給heatmap函數的數據框的row.names信息)擁擠x軸,並且我無法弄清楚如何控制標籤。R熱圖中的控制軸標記

下面是一個例子:

vDates = seq.Date(from = as.Date('29-11-2012', 
           format = '%d-%m-%Y'), 
       length.out = 203, by = 'day') 
dfHeatMap = rdirichlet(length(vDates), runif(15)) 
row.names(dfHeatMap) = as.character(vDates) 
heatmap(t(dfHeatMap), Rowv = NA, Colv = NA, 
     col = cm.colors(256)) 

Crowded heatmap

任何建議/包是對待這個問題的關心?

+0

請讓你的示例代碼可重現通過包括必要的程序包。 – Roland

+0

@Roland謝謝! – tchakravarty

回答

1

我能夠RTFM(更仔細地)圖了這一點。最初,我是不是能夠得到labCollabRow工作。下面是一個工作示例:

library(gtools) 
library(ClassDiscovery) 

# generate sequence of dates 
vDates = seq.Date(from = as.Date('29-11-2012', 
           format = '%d-%m-%Y'), 
        length.out = 203, by = 'day') 

# generate the random samples 
dfHeatMap = as.matrix(rdirichlet(length(vDates), runif(15))) 
row.names(dfHeatMap) = as.character(vDates) 


# column labels 
vDatesNew = rep(as.Date(NA), length(vDates)) 
vDatesNew[seq(from = 1, to = 203, by = 10)] = 
    vDates[seq(from = 1, to = 203, by = 10)] 

# row labels 
labRow = c(NA, NA, 3, NA, NA, 6, NA, NA, 9, 
      NA, NA, 12, NA, NA, 15) 

# draw the heatmap with aspect control 
aspectHeatmap(t(dfHeatMap), Rowv = NA, Colv = NA, 
       col = cm.colors(256), labCol = vDatesNew, labRow = labRow, 
       margins = c(5, 5), hExp = 1.5, wExp = 4) 

我已經使用了包ClassDiscovery以控制熱圖的縱橫比。這是什麼樣子: enter image description here