我想在热图上绘制一个连续变量(称为值),具体取决于日期和时间。
我展示了data.frame的标题:
> data
value hour day
1 4.0775374 17 martes
2 5.9107966 13 martes
3 3.9318256 12 martes
4 2.9444390 10 martes
5 4.9767337 17 lunes
6 3.7841896 13 lunes
7 4.9904326 11 lunes
8 3.1780538 20 domingo
9 2.9444390 19 domingo
10 3.6635616 16 domingo
11 2.7080502 14 domingo
12 2.8903718 21 sábado
13 2.0794415 15 sábado
14 4.3944492 14 sábado
15 2.1972246 12 sábado
16 2.0794415 12 sábado
17 1.9459101 11 sábado
18 4.3694479 19 viernes
19 3.5835189 11 viernes
20 2.9957323 19 jueves
21 2.4849066 15 jueves
22 3.7376696 13 jueves
23 2.1972246 11 jueves
24 2.0794415 10 jueves
25 5.6664267 20 miércoles
26 6.1800167 18 miércoles
.. ... .. .......
186 2.5649494 13 domingo
R代码:
ggplot(data = data,aes(x=day, y=hour, fill=value)) +
geom_tile() +
scale_fill_continuous(low = 'yellow', high = 'blue')+
theme_classic()
输出:
问题:我需要在热图中填充黑色方块的空方块(非NA值)。
解决方案:
data = data %>% complete(hour, nesting(day))
稍后,将na.value = 'color'
添加到scale_fill_continuous
功能。
答案 0 :(得分:0)
你快到了!只需在na.value = 'salmon'
中添加scale_fill_continuous
或您喜欢的任何颜色,如下所示:
ggplot(data = data,aes(x=day, y=hour, fill=value)) +
geom_tile() +
scale_fill_continuous(low = 'yellow', high = 'blue', na.value = 'salmon')+
theme_classic()