hc_yAxis的多个类别

问题描述 投票:0回答:1

现在尝试了很长时间,但找不到解决方案。我尝试得到类似于那个的东西:

https://www.highcharts.com/demo/parallel-coordinates

所以我有多个Y轴,它们具有不同的类别变量。但是在R中,我只能定义第一个Axis。不知道为什么我的解决方案不起作用。这里是一个例子:

library(highcharter)

df2 <- data.frame(name = c(2,2,2),y = c(0,1,2))
df3 <- data.frame(name = c(3,3,3),y = c(1,1,3))
df4 <- data.frame(name = c(4,4,4),y = c(2,0,1))

hc <- highchart()%>%
  hc_xAxis(categories = list("From","Node","To"))%>%
  hc_chart(zoomType = "xy",type = "spline", parallelCoordinates = TRUE)%>%
  hc_title(text = 'Marathon set')%>%
  # hc_yAxis(categories = list("S12","S19","S16"))%>%
  hc_yAxis(categories = list(
    list(categories = list("S12","S10","S16")),
    list(categories = list("A3","A5","B7")),
    list(categories = list("S15","S16","S20"))))%>%
  hc_add_series(name = "test2", data = df2)%>%
  hc_add_series(name = "test3", data = df3)%>%
  hc_add_series(name = "test4", data = df4)
hc 

您看,输出不是我在第二个和第三个Y轴上期望的。

我希望有人可以提供帮助。

r list dataframe highcharts yaxis
1个回答
0
投票

您不能定义包含多个类别数组的类别数组。您需要使用hc_yAxis_multiples定义单独的y轴:

library(highcharter)

df2 <- data.frame(name = c(2,2,2),y = c(0,1,2))
df3 <- data.frame(name = c(3,3,3),y = c(1,1,3))
df4 <- data.frame(name = c(4,4,4),y = c(2,0,1))

hc <- highchart()%>%
  hc_xAxis(categories = list("From","Node","To"))%>%
  hc_chart(zoomType = "xy",type = "spline", parallelCoordinates = TRUE)%>%
  hc_title(text = 'Marathon set')%>%
  # hc_yAxis(categories = list("S12","S19","S16"))%>%
  hc_yAxis_multiples(
    list(categories = list("S12","S10","S16")),
    list(categories = list("A3","A5","B7")),
    list(categories = list("S15","S16","S20"))
  ) %>% 
  hc_add_series(name = "test2", data = df2)%>%
  hc_add_series(name = "test3", data = df3)%>%
  hc_add_series(name = "test4", data = df4)
hc 
© www.soinside.com 2019 - 2024. All rights reserved.