我想制作一个折线图,其中包含一个共享两个y轴的x轴,一个在左侧,另一个在右侧的在R 中。
我找到了许多关于如何做到这一点的例子,但是我没有设法用R&C包装" highcharter"来重现它。
以下是示例:
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")
)
有没有人有想法?
谢谢!
答案 0 :(得分:8)
在高级官方网站上有一个带有两个轴的演示:
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)
答案 1 :(得分: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)