简体   繁体   English

R 中 Highcharter 中的两个 y 轴

[英]Two y Axis in Highcharter in R

I would like to make a line chart containing one x axis sharing two y axis, one on the left side and the second one on the right of the plot in R .我想制作一个折线图,其中包含一个 x 轴共享两个 y 轴,一个在左侧,第二个在 R中的绘图右侧。

I found many examples on how to do this but I don't manage to reproduce it in R with the package "highcharter".我找到了很多关于如何执行此操作的示例,但我无法使用“highcharter”包在 R 中重现它。

Here are the examples :以下是示例:

http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/highcharts/yaxis/opposite/ http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/highcharts/yaxis/opposite/

http://www.highcharts.com/demo/combo-dual-axes http://www.highcharts.com/demo/combo-dual-axes

Here what I have done so far :这是我到目前为止所做的:

g <- highchart()%>%
hc_xAxis(categories = c("2016-01-01","2016-02-01","2016-03-01","2016-04-01","2016-05-01","2016-06-01","2016-07-01","2016-08-01","2016-09-01","2016-10-01"))%>%
hc_yAxis(
  list(title = list(text = "Yaxis1")),
  list(title = list(text = "Yaxis2"), opposite = TRUE)
)%>%
hc_series(
  list(yAxis = 0, data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3), name = "Data1"),
  list(yAxis = 1, data = c(8.0, 7.9, 10.5, 15.5, 19.2, 22.5, 28.2, 23.5, 21.3, 14.3), name = "Data2")
)

Does anyone have an idea ?有没有人有想法?

Thank you !谢谢!

In the highcharter official website there is a demo with two axis:在highcharter官网有一个带两个轴的demo:

http://jkunst.com/highcharter/highcharts.html#highcharts-home-page-demo http://jkunst.com/highcharter/highcharts.html#highcharts-home-page-demo

在此处输入图片说明

You need to use hc_yAxis_multiples in this case:在这种情况下,您需要使用hc_yAxis_multiples

highchart() %>% 
  hc_yAxis_multiples(
    list(lineWidth = 3),
    list(showLastLabel = FALSE, opposite = TRUE)
  ) %>% 
  hc_add_series(data = rnorm(10)) %>% 
  hc_add_series(data = rexp(10), type = "spline", yAxis = 1)

The 'two-axis' demo mentioned isn't on the web-site any more!提到的“双轴”演示不再出现在网站上!

Here is an example derived from jbkunst 's own help documentation ?hc_yAxis_multiples这是一个源自jbkunst自己的帮助文档的示例?hc_yAxis_multiples

In particular, it shows how to place titles on those separate y-axes...特别是,它展示了如何在这些单独的 y 轴上放置标题......

aapl <- quantmod::getSymbols("AAPL", 
                             src = "yahoo",
                             from = "2020-01-01",
                             auto.assign = FALSE
)

# Plot prices and volume with relative height.
highchart(type = "stock") %>%
    hc_title(text = "AAPLE") %>%
    hc_yAxis_multiples(list(title = list(text = "Price"), opposite = FALSE),
                       list(showLastLabel = FALSE, opposite = TRUE, title = list(text = "Volume"))) %>%
    hc_add_series(aapl, yAxis = 0, showInLegend = FALSE) %>%
    hc_add_series(aapl[, "AAPL.Volume"], yAxis = 1, type = "column", showInLegend = FALSE)

多 Y 轴标注

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

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