簡體   English   中英

當存在負值時,highcharter 熱圖不遵循 hc_coloraxis

[英]highcharter heatmap not following hc_coloraxis when there's negative values


你好。
我試圖按照 hc_colorAxis 的停止參數中的設計將顏色設置為從 -1 到 1。 如果相關矩陣中沒有負值,這可以正常工作。 但是,當存在負值時,它會重置為藍色、白色和紅色這些默認顏色。

這是帶有數據的代碼:

 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")))

這是我得到的: 在此處輸入圖片說明


這就是我想要得到的(將 t1 中的“SH”替換為“AAPL”):

在此處輸入圖片說明

任何幫助表示贊賞!

您如何看待遍歷所有點,找到具有負 colorValue 的點然后更改它們的顏色?

喜歡這個演示: https : //jsfiddle.net/BlackLabel/7p0ufcma

然后你可以使用 Highcharts JS API。 您可以在此處查看有關如何執行此操作的便捷文章: 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM