Highcharts Heatmap在R中未正确渲染

l7mqbcuq  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(206)

我试图从这个链接复制一个highcharter热图:https://jkunst.com/highcharter/articles/showcase.html
下面的代码:

library(highcharts)
library(dplyr)
library(magrittr)
library(htmlwidgets)

fntltp <- JS("function(){
  return this.point.x + ' ' +  this.series.yAxis.categories[this.point.y] + ': ' +
  Highcharts.numberFormat(this.point.value, 2);
}")

joindf %>% 
hchart(
  "heatmap", 
  hcaes(
    x = Year,
    y = title, 
    value = ave_sentiment,
    )
  ) %>%
  hc_colorAxis(
    stops = color_stops(10, viridisLite::inferno(10, direction = -1)),
    type = "logarithmic"
  ) %>% 
  hc_yAxis(
    title = list(text = ""),
    reversed = TRUE, 
    offset = -20,
    tickLength = 0,
    gridLineWidth = 0, 
    minorGridLineWidth = 0,
    labels = list(style = list(fontSize = "9px"))
  ) %>% 
  hc_tooltip(
    formatter = fntltp
    ) %>% 
  hc_title(
    text = "Impact of User Synergy Levels"
    ) %>% 
  hc_subtitle(
    text = "Average Synergy scores per posts"
  ) %>% 
  hc_legend(
    layout = "horizontal",
    verticalAlign = "top",
    align = "left",
    valueDecimals = 0
  ) %>% 
  hc_size(height = 900)

当我执行代码时,我只得到图表名称和图例,而不是热图本身。

数据:https://www.dropbox.com/s/42oezb75pt3i1u4/joindf.csv?dl=0
任何帮助都是感激的,我正在弄清楚为什么这个情节没有渲染。

hgb9j2n6

hgb9j2n61#

如果您将hc_colorAxis的类型参数更改为“linear”,并从 Dataframe 中删除NA,则会得到以下结果:

library(tidyverse)
joindf <- joindf %>% 
  select(-1) %>% 
  drop_na() 

joindf %>% 
  hchart(
    "heatmap", 
    hcaes(
      x = Year,
      y = title, 
      value = ave_sentiment,
    )
  ) %>% 
  hc_colorAxis(
    stops = color_stops(10, viridisLite::inferno(10, direction = -1)),
    type = "linear"
  ) %>% 
  hc_yAxis(
    title = list(text = ""),
    reversed = TRUE, 
    offset = -20,
    tickLength = 0,
    gridLineWidth = 0, 
    minorGridLineWidth = 0,
    labels = list(style = list(fontSize = "9px"))
  ) %>% 
  hc_tooltip(
    formatter = fntltp
  ) %>% 
  hc_title(
    text = "Impact of User Synergy Levels"
  ) %>% 
  hc_subtitle(
    text = "Average Synergy scores per posts"
  ) %>% 
  hc_legend(
    layout = "horizontal",
    verticalAlign = "top",
    align = "left",
    valueDecimals = 0
  ) %>% 
  hc_size(height = 900)

相关问题