在 Highcharter 中创建索引条形图

Creating an index bar chart in Highcharter

我正在尝试创建一个条形图,显示索引到 U.S 的生活费用。 R 中 Highcharter 包中的值 (100)。所以我希望条形图从 100 开始,然后延伸到 100 的右侧或左侧。我有基本的条形图,但我不知道如何移动图表的中心线到 100。我试图让它看起来像这样:http://drawingwithnumbers.artisart.org/moving-the-center-line-of-a-bar-chart-with-a-gantt-chart/

这是我正在处理的数据:

States <- c('Tennessee','Michigan','Indiana','Ohio','Kentucky','West Virginia','North Carolina','Virginia','Pennsylvania','Delaware','New Jersey','Maryland','New York')
Cost_of_Living <- c(88.7,88.9,90,90.8,90.9,91.1,94.9,100.7,101.7,108.1,125.1,129.7,139.1)
costliving <- data.frame(States, Cost_of_Living)

这是我的条形图代码,只是基本条形图

costliving_graph <- highchart() %>% 
  hc_title(text = "Cost of Living by State (2020)") %>%
  hc_add_series (costliving, "bar", hcaes(x = States, y = Cost_of_Living)) %>%
  hc_xAxis(categories = costliving$States) %>%
  hc_yAxis(title = list(text = "Indexed to the U.S. (U.S. Value = 100)"))%>%
  hc_plotOptions (bar = list(colorByPoint = TRUE)) %>%
  hc_legend (enabled = FALSE)%>%
  hc_tooltip(pointFormat = "MSA Regional Price Parities: {point.y}", headerFormat ="")
costliving_graph

任何帮助都会很棒!提前致谢

检查 highcharter 网站上的示例后,我将图表类型更改为 columnrange 并向数据框添加了新变量 lowhigh。试试这个:

library(highcharter)
library(dplyr)

States <- c('Tennessee','Michigan','Indiana','Ohio','Kentucky','West Virginia','North Carolina','Virginia','Pennsylvania','Delaware','New Jersey','Maryland','New York')
Cost_of_Living <- c(88.7,88.9,90,90.8,90.9,91.1,94.9,100.7,101.7,108.1,125.1,129.7,139.1)
costliving <- data.frame(States, Cost_of_Living) %>% 
  mutate(low = pmin(Cost_of_Living, 100),
         high = pmax(Cost_of_Living, 100))

costliving_graph <- highchart() %>% 
  hc_title(text = "Cost of Living by State (2020)") %>%
  hc_add_series(costliving, "columnrange", hcaes(x = States, y = Cost_of_Living, low = low, high = high)) %>%
  hc_xAxis(categories = costliving$States) %>%
  hc_yAxis(title = list(text = "Indexed to the U.S. (U.S. Value = 100)"))%>%
  hc_plotOptions (bar = list(colorByPoint = TRUE)) %>%
  hc_legend (enabled = FALSE)%>%
  hc_tooltip(pointFormat = "MSA Regional Price Parities: {point.y}", headerFormat ="")
costliving_graph