如何在R highcharter中反转多个y轴?

问题描述 投票:0回答:1

我想使用highchater库在R中反转多个y轴图表。不幸的是,当我指定用途hc_chart(iverted=T)时,它会移动一个轴,其余的则不会移动其位置。这是来自jbkunst的示例:https://rpubs.com/jbkunst/create_yaxis

library("highcharter");library(dplyr)

highchart() %>%
# probably I should specify "inverted=T" in "hc_yAxis_multiples"
  hc_yAxis_multiples(create_yaxis(naxis = 4, title = list(text = NULL))) %>%
  hc_add_series(data = c(1,3,2)) %>%
  hc_add_series(data = c(20, 40, 10), yAxis = 1) %>%
  hc_add_series(data = c(200, 400, 500), type = "column", yAxis = 2) %>%
  hc_add_series(data = c(500, 300, 400), type = "column", yAxis = 2) %>% 
  hc_add_series(data = c(5,4,7), type = "spline", yAxis = 3)

这是我想采用的一个例子。 https://jsfiddle.net/BlackLabel/cdok7w0L/

r highcharts data-visualization visualization
1个回答
0
投票

如果您想将多个y轴与倒置图表结合,建议您手动定义它们(不使用create_yaxis方法,请参阅:

library("highcharter");

highchart() %>%
  hc_chart(inverted=T) %>%
  hc_yAxis_multiples(
    list(width = '30%'),
    list(width = '30%', left = '35%', offset = 0),
    list(width = '30%', left = '70%', offset = 0)
  ) %>%
  hc_add_series(data = c(1,3,2)) %>%
  hc_add_series(data = c(20, 40, 10), yAxis = 1) %>%
  hc_add_series(data = c(200, 400, 500), type = "column", yAxis = 2)

另外,您在“ hc_chart(inverted = T)%>%中有一个错字。

在您在jsFiddle中提供的示例中,每个图表都有单独的容器。在您的示例中,您有一个容器,但有多个系列连接到单独的轴,因此您需要定义它们的宽度和左偏移。

让我知道您是否还有其他问题。

© www.soinside.com 2019 - 2024. All rights reserved.