2017-07-06 51 views
0

有幾個類似的問題,但他們沒有問我在找什麼。 我有一個基因表達數據與多個獨立變量。我想用R中的熱圖可視化它。我不能將所有三個變量都包含在熱圖上。以下是示例代碼:在R中生成熱圖(多個自變量)

species <- rep(c("st", "rt"), each = 18) 
life <- rep(c("5d", "15d", "45d"), 2, each = 6) 
concentration <- rep(c("c1", "c2", "c3"), 6, each = 2) 
gene <- rep(c("gene1", "gene2"), 36, each = 1) 
response <- runif(36, -4, 4) 
data1 <- data.frame(species, life, concentration, gene, response) 

我可以使用任何軟件包。請看下面的圖片來自不同的數據集。我希望以類似的方式可視化我的數據。

example_data_visualized

非常感謝提前!

回答

0

我不知道它在你的代碼的變量對應於你的圖表中的尺寸,但使用ggplot2包,這是很容易做到這一點:

library(ggplot2) 

ggplot(data1, aes(x = factor(life, levels = c("5d", "15d", "45d")), 
        y = concentration, 
        fill = response)) + 
    geom_tile() + 
    facet_wrap(~species + gene, nrow = 1) + 
    scale_fill_gradient(low = "red", high = "green", guide = FALSE) + 
    scale_x_discrete(name = "life") 

當然,你可以相應地調整標題,標籤,顏色等。