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

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

我正在尝试执行以下操作:我有关于我公司的两个数据集。例如,第一个有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轴的不同类别数组:类似于具有“两个hc_xAxis”控件的可能性,在这里我可以为每个绘制的序列指定自己的类别。我的最终目标是在解析每个不同的列时使用卖方的名字。希望我足够清楚:)谢谢

r highcharts r-highcharter multiple-axes
1个回答
0
投票

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"
  )
© www.soinside.com 2019 - 2024. All rights reserved.