简体   繁体   English

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

[英]How to invert multiple y-axis in R highcharter?

I want to invert a multiple y-Axis chart in R using highchater library.我想使用 highchater 库在 R 中反转多 y 轴图表。 Unfortunately, when I specify the use hc_chart(iverted=T) , it moves one axis, the rest do not move their position.不幸的是,当我指定使用hc_chart(iverted=T) ,它移动一个轴,其余的不移动它们的位置。 Here is an example from jbkunst: https://rpubs.com/jbkunst/create_yaxis以下是 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)

Here is an example that I would like to adopt.这是我想采用的一个例子。 https://jsfiddle.net/BlackLabel/cdok7w0L/ https://jsfiddle.net/BlackLabel/cdok7w0L/

If you want to have multiple y-axes combined with the inverted chart, I suggest defining them manually (without create_yaxis method), see:如果你想将多个 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)

Also, you have a typo in " hc_chart(inverted=T) %>% "另外,您在“ hc_chart(inverted=T) %>% ”中有一个错字

In the example you provided in jsFiddle, there are separate containers for each chart.在您在 jsFiddle 中提供的示例中,每个图表都有单独的容器。 In your example, you have one container but many series connected to a separate axis, so you need to define their width and left offset.在您的示例中,您有一个容器,但许多系列连接到一个单独的轴,因此您需要定义它们的宽度和左偏移量。

API Reference: https://api.highcharts.com/highcharts/yAxis.width https://api.highcharts.com/highcharts/yAxis.left API参考: https : //api.highcharts.com/highcharts/yAxis.width https://api.highcharts.com/highcharts/yAxis.left
https://api.highcharts.com/highcharts/yAxis.offset https://api.highcharts.com/highcharts/yAxis.offset

Let me know if you have any further questions.如果您有任何其他问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM