无法绘制热图

时间:2019-11-21 00:48:02

标签: r ggplot2 heatmap ggplotly

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
Apartment_no <- c("1-SV","1-SV","1-SV","1-SH","1-SH","1-SH","1-1V","1-1V","1-1V","1-1H","1-1H","1-1H","3-SV","3-SV","3-SV","3-1V","3-1V","3-1V","3-1H","3-1H","3-1H")
month <- c("September","October","November","September","October","November","September","October","November","September","October","November","September","October","November","September","October","November","September","October","November")
Days <- c(NA,19,28,2,19,28,2,19,NA,2,19,28,25,31,28,12,NA,24,8,26,19)
Heat_clean <- data.frame(Apartment_no,month,Days)

这只是一个样本数据集。实际上,我大约有163个apartment_no和所有月份的数据。我希望为其创建一个交互式的热图,因为数据很大。我希望使用特殊的颜色代码,即每当Days == NA,color = Red,1 <= Days <= 5,color = Blue,6 <= Days <= 15,color = Orange,16 <= Days <= 25,颜色=粉红色,25 <=天数<= 31,颜色=绿色。我已经使用了以下代码,但是它对我不起作用,实际上给了我一个错误消息,因为“ x必须是一个数字矩阵”。我的代码如下:

> mypallete <- colorRampPalette(Days=na.color,col="Red", 1<=Days<=5,col="Blue", 6<=Days<=15,col="Orange", 16<=Days<=25,col="Pink", 25<=Days<=31,color=Green)

> heatmap.2(as.matrix(Heat_clean),Rowv = F,Colv = F,main = "Heatmeters data",col = mypallete,dendrogram = "none",density.info = "none",trace = "none")

我首先定义了自己的调色板,然后在代码中实现了它。我希望获得一些可以在图中看到的东西,尽管使用我的个性化颜色编码。也许以后我可以将代码插入plot_ly以使其具有交互性。 enter image description here

1 个答案:

答案 0 :(得分:0)

您的范围不是排他性的(use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions tell application "Finder" set _folder to choose folder set _files to files of _folder repeat with _file in _files if creator type of _file is "MSWD" then tell application "Microsoft Word" open _file set _doc to document of window 1 save as _doc file format format text close _doc end tell end if end repeat end tell delay 5),但是很容易解决...

我不认为您的数据结构与Days <= 25所期望的相符,这就是给您带来错误的原因,而不是颜色映射。

这是一种生成调色板的暴力方式...(请注意,我更改了25 <= Days的拼写)

heatmap.2