我想使用R中的heatmap
highchart
绘图库为我的数据绘制js
->
library(highcharter) library(dplyr) library(chron) library(viridisLite ) fntltp <- JS("function(){ return this.series.yAxis.categories[this.point.y] + this.point.x + ':' + ':<br>' + Highcharts.numberFormat(this.point.value, 4); }") Data = data.frame(Time1 = seq(as.POSIXct('2020-04-30 00:00:00', tz = "UTC"), as.POSIXct('2020-05-06 00:00:00', tz = "UTC"), by = '10 min')) %>% mutate(Date = paste(substr(weekdays(as.Date(Time1, tz = "UTC")), 1, 3), format(as.Date(Time1, tz = "UTC"), "%b,%d"), " "), 'Value' = runif(865, -1, 1), Time = times(format(Time1, "%H:%M:%S"))) hchart(Data, "heatmap", hcaes(x = Time, y = Date, value = Value)) %>% hc_colorAxis(stops = color_stops(30, rev(viridis(30)))) %>% hc_yAxis(reversed = TRUE, offset = 2, tickLength = 0, gridLineWidth = 0, minorGridLineWidth = 0, labels = list(style = list(fontSize = "12px"))) %>% hc_xAxis(labels = list(type = 'datetime', dateTimeLabelFormats = list(day = '%H:%M'))) %>% hc_legend(layout = "vertical", verticalAlign = "middle", align = "right", valueDecimals = 0) %>% hc_size(height = 800) %>% hc_tooltip(formatter = fntltp)
显然,当我的
x-axis
格式化为HH:MM
(及时)时,这不是正确的绘图。另外,在legend
中,x-axis
的值也未正确输入。
此外,y-axis
的顺序也不平滑,因为我想让最下面的第一天位于顶部,第一天位于顶部。
任何指针如何纠正这些不规则都会很有帮助。
根据@ raf18seb的回复修改的帖子-
下面是我的简化数据的新图-
library(highcharter) library(dplyr) library(chron) set.seed(1) Data = data.frame(Time1 = seq(as.POSIXct('2020-04-30 00:00:00', tz = "UTC"), as.POSIXct('2020-05-06 00:00:00', tz = "UTC"), by = '10 min')) %>% mutate(Date = paste(substr(weekdays(as.Date(Time1, tz = "UTC")), 1, 3), format(as.Date(Time1, tz = "UTC"), "%b,%d"), " "), 'Value' = runif(865, -1, 1), Day_Time = as.character(times(format(Time1, "%H:%M:%S")))) tail(Data) hchart(Data, "heatmap", hcaes(x = Day_Time, y = Date, value = Value)) %>% hc_yAxis(reversed = TRUE, offset = 2, tickLength = 0, gridLineWidth = 0, minorGridLineWidth = 0, labels = list(style = list(fontSize = "12px"))) %>% hc_xAxis(labels = list(type = 'datetime', dateTimeLabelFormats = list(day = '%H:%M'))) %>% hc_size(height = 800)
有了这个,我想在下面实现-
HH:MM
而不是HH:MM:SS
。increasing order of day
中排序。即5月6日应该在底部,4月30日应该在顶部read (for -1)
开始并在green (+1)
和yellow for (0)
处结束<Value: data-value><br><Date: date as in y-axis><br><Time: Time as in x-axis in HH:MM format>
任何指针如何实现它们都将非常有帮助
[我想使用R中的highchart js绘图库为我的数据绘制热图-库(highcharter)库(dplyr)库(chron)库(viridisLite)fntltp
简短的回答:您的数据有问题。
说明:我设法从您的R图表中获取了您的数据。您有865分,简化后的数据如下: