我在R中使用 highcharter 包。当我创建一个highchart对象时,似乎我必须在hc_yAxis函数中添加y轴。例如
library(highcharter)
library(PerformanceAnalytics)
data(edhec)
R = edhec[, 1:3]
height = 650
columns = ncol(R)
top = 1.1/2.9 * height/(2 + columns)
hc <- highchart(type = "stock")
hc <- hc_yAxis(hc,
list(height = height/(2 + columns)),
list(height = height/(2 + columns), top = top + height/(1 + columns)),
list(height = height/(2 + columns), top = top + 2*height/(1 + columns)))
for(i in 1:columns) {
hc <- hc_add_series_xts(hc, R[, i], yAxis = i - 1)
}
hc <- hc_scrollbar(hc, enabled = TRUE) %>%
hc_add_theme(hc_theme_538())
hc
如何根据R?
中的列数自动将y轴添加到我的图形中答案 0 :(得分:2)
现在有一个函数可以创建任意数量的yAxis
。它被称为create_yaxis
(您需要下载开发版本):
library(highcharter)
library(PerformanceAnalytics)
data(edhec)
R <- edhec[, 1:3]
hc <- highchart(type = "stock")
hc <- hc_yAxis_multiples(hc, create_yaxis(naxis = 3, heights = c(2,1,1)))
for(i in 1:ncol(R)) {
hc <- hc_add_series_xts(hc, R[, i], yAxis = i - 1, name = names(R)[i])
}
hc <- hc_scrollbar(hc, enabled = TRUE) %>%
hc_add_theme(hc_theme_flat())
hc
您可以在此处查看示例:http://rpubs.com/jbkunst/create_yaxis