在热图中缩放图例

时间:2020-01-27 12:54:19

标签: r ggplot2

我已使用此处的代码创建了一个图形:https://nitinahuja.github.io/2017/heatmaps-in-r/

但是,当我绘制图表时,所有正方形都是相同的颜色。如何重新设置图例/缩放比例以确保热图能够捕获数据的可变性?

ggplot(Change , aes(x=Hour, y=Day, fill = Range)) + 
+     geom_tile(color = "white", size = 0.2) + 
+     scale_x_discrete(expand=c(0,0)) + 
+     scale_y_discrete(expand=c(0,0)) + 
+     scale_fill_viridis(name="Price Range", option = "plasma") + 
+     coord_equal() + 
+     labs(x="Hour", y=NULL, title=sprintf("price range by hr")) + 
+     theme_tufte(base_family="Helvetica") +
+     theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

我正在使用的数据的一部分:

Row   Date        Hour     Day    Range
1   2020-01-22  1:00    Wednesday   31.9
2   2020-01-22  0:00    Wednesday   31.7
3   2020-01-21  23:00   Tuesday     29.5
4   2020-01-21  22:00   Tuesday     51.8
5   2020-01-21  21:00   Tuesday      82.3
6   2020-01-21  20:00   Tuesday      197.5
7   2020-01-21  19:00   Tuesday     296.7
8   2020-01-21  18:00   Tuesday      33.4
9   2020-01-21  17:00   Tuesday      24.9
10  2020-01-21  16:00   Tuesday      35.2
11  2020-01-21  15:00   Tuesday       37.3
12  2020-01-21  14:00   Tuesday      15.2
13  2020-01-21  13:00   Tuesday      23.0
14  2020-01-21  12:00   Tuesday      27.0
15  2020-01-21  11:00   Tuesday       31.8
16  2020-01-21  10:00   Tuesday       74.0
17  2020-01-21  9:00    Tuesday       33.6
18  2020-01-21  8:00    Tuesday       41.7
19  2020-01-21  7:00    Tuesday       33.1
20  2020-01-21  6:00    Tuesday       27.5
21  2020-01-21  5:00    Tuesday       40.7
22  2020-01-21  4:00    Tuesday       23.8
23  2020-01-21  3:00    Tuesday       19.5
24  2020-01-21  2:00    Tuesday       19.0
25  2020-01-21  1:00    Tuesday       21.8
26  2020-01-21  0:00    Tuesday       47.0
27  2020-01-20  23:00   Monday        62.5
28  2020-01-20  22:00   Monday        91.8
29  2020-01-20  21:00   Monday        28.6
30  2020-01-20  20:00   Monday        12.4

enter image description here

0 个答案:

没有答案
相关问题