【问题标题】:Two y Axis in Highcharter in RR中Highcharter中的两个y轴
【发布时间】:2016-10-17 10:48:24
【问题描述】:

我想制作一个折线图,其中包含一个 x 轴共享两个 y 轴,一个在左侧,第二个在绘图的右侧in R

我找到了很多关于如何做到这一点的示例,但我无法使用包“highcharter”在 R 中重现它。

这里是例子:

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

这是我到目前为止所做的:

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")
)

有人有想法吗?

谢谢!

【问题讨论】:

    标签: r highcharts


    【解决方案1】:

    highcharter官网上有一个带两个轴的demo:

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

    在这种情况下你需要使用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)
    

    【讨论】:

    • 你如何引用 YAxis 0 或 1 在hc_yAxis 中进行格式化? IE。 labels_YAxis0 = list(format = "{value} mm")
    • x轴有类似的功能吗?我希望为水平堆积条形图引入辅助轴...
    【解决方案2】:

    网站上不再提及“双轴”演示!

    这是一个源自jbkunst自己的帮助文档?hc_yAxis_multiples的示例

    特别是,它展示了如何在这些单独的 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-24
      • 2023-03-18
      • 1970-01-01
      • 2018-08-18
      • 1970-01-01
      • 1970-01-01
      • 2022-06-22
      • 1970-01-01
      相关资源
      最近更新 更多