[英]highcharter heatmap not following hc_coloraxis when there's negative values
Here is the code with data:这是带有数据的代码:
library(BatchGetSymbols) library(tidyverse) library(highcharter) t1 = BatchGetSymbols(c("MSFT", "SPY", "SH"))[[2]] t2 = t1[,c("ticker", "ref.date", "ret.adjusted.prices")] t3 = na.omit(pivot_wider(t2, names_from = ticker, values_from = "ret.adjusted.prices")) t4 = cor(t3[,2:4]) hchart(type = "heatmap", t4) %>% hc_legend(layout = "vertical", verticalAlign = "middle", align = "right") %>% hc_colorAxis(min = -1, max = 1, stops = color_stops(3, c("#d51f3a", "#FFFFFF", "#5daa45")))
Here is what I am getting:这是我得到的:
Any help is appreciated!任何帮助表示赞赏!
What do you think about looping through all points, finding ones that have negative colorValue and then changing their color?您如何看待遍历所有点,找到具有负 colorValue 的点然后更改它们的颜色?
Like this demo: https://jsfiddle.net/BlackLabel/7p0ufcma喜欢这个演示: https : //jsfiddle.net/BlackLabel/7p0ufcma
Then you could use the Highcharts JS API.然后你可以使用 Highcharts JS API。 You can see a handy article on how to do it here: https://www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR3UzztbrY4rdCbOw1W7DmSq4mWJswJZxIw-xOqGbjIRExj-gsuVEO2zM00您可以在此处查看有关如何执行此操作的便捷文章: https : //www.highcharts.com/blog/tutorials/working-with-highcharts-javascript-syntax-in-r/?fbclid=IwAR3UzztbrY4rdCbOw1W7DmSq4mWJswJZxIw-xOqGbsu0G02M2M
chart.series[0].data.forEach(point => {
if (point.colorValue < 0) {
point.update({
color: 'red'
});
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.