R highcharter - 同一图中具有不同 X 轴的两个条形图

R highcharter - Two barchart in same plot with different X-axis

我正在尝试执行以下操作:

我有两个关于我公司的数据集。例如,第一个有增长最快的 20 个卖家。第二个有倒数 20 个亏损的卖家。所以,它是这样的:

growing_seller <- c("a","b","c","d","e","f","g","h","i","h")
sales_yoy_growing <- c(100000,90000,75000,50000,37500,21000,15000,12000,10000,8000)
top_growing <- data.frame(growing_seller,sales_yoy_growing)


losing_seller <- c("i","j","k","l","m","n","o","p","q","r")
sales_yoy_losing <- c(-90000,-75000,-50000,-37500,-21000,-15000,-12000,-10000,-8000,-5000)
bottom_losing <- data.frame(losing_seller,sales_yoy_losing)

我正在尝试使用与卖家名称相对应的不同类别在同一图中绘制两个图表。所以我到目前为止是这样的:

library(highcharter)

growing_seller <- c("a","b","c","d","e","f","g","h","i","h")
sales_yoy_growing <- c(100000,90000,75000,50000,37500,21000,15000,12000,10000,8000)
top_growing <- data.frame(growing_seller,sales_yoy_growing)

losing_seller <- c("i","j","k","l","m","n","o","p","q","r")
sales_yoy_losing <- c(-90000,-75000,-50000,-37500,-21000,-15000,-12000,-10000,-8000,-5000)
bottom_losing <- data.frame(losing_seller,sales_yoy_losing)

highchart() %>%
  hc_add_series(
    data = top_growing$sales_yoy_growing,
    type = "column",
    grouping = FALSE
  ) %>%

  hc_add_series(
    data = bottom_losing$sales_yoy_losing,
    type = "column"
  )

这就是我想以图形方式实现的:Chart example
现在,我希望每个独立的 x 轴有一个 不同的类别数组 :类似于拥有 "two hc_xAxis" 控件的可能性,我可以在其中为每个绘制的系列指定其自己的类别。
然后,我的最终目标是在解析每个不同的列时获得卖家的名称。

希望我说得够清楚 :)
谢谢

Highcharts 默认在工具提示中显示点的名称。您只需要在数据中指向 name 值。 你可以这样做: top_growing <- data.frame(name = growing_seller, y = sales_yoy_growing)

这是完整的代码:

library(highcharter)

growing_seller <- c("a","b","c","d","e","f","g","h","i","h")
sales_yoy_growing <- c(100000,90000,75000,50000,37500,21000,15000,12000,10000,8000)
top_growing <- data.frame(name = growing_seller, y = sales_yoy_growing)

losing_seller <- c("i","j","k","l","m","n","o","p","q","r")
sales_yoy_losing <- c(-90000,-75000,-50000,-37500,-21000,-15000,-12000,-10000,-8000,-5000)
bottom_losing <- data.frame(name = losing_seller, y = sales_yoy_losing)

highchart() %>%
  hc_add_series(
    data = top_growing,
    type = "column",
    grouping = FALSE
  ) %>%

  hc_add_series(
    data = bottom_losing,
    type = "column"
  )