0

I am trying to do the following:

I have a two datasets about my company. The first one has, say, the top 20 growing sellers. The second one has the bottom 20 losing sellers. So, it's something like this:

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)

I am trying to plot both charts in the same plot using DIFFERENT categories, corresponding to the sellers' name. So what I have so far is this:

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"
  )

This is what I want to achieve graphically: Chart example
Now,I would like to have a different category array per each independent x-axis: something like the possibility to have "two hc_xAxis" controls, where I could specify per each plotted series its own categories.
My final aim is to, then, have the seller's name as I parse over each of the different columns.

Hope I was clear enough :)
Thanks

Lorenzo
  • 17
  • 4
  • Sorry, but I am not sure if I understood you well. Are you trying to achieve something like this? https://jsfiddle.net/BlackLabel/ot8c3j1g/ or something like this? https://jsfiddle.net/BlackLabel/o0e37fjx/ first, let's get it in JavaScript, and then I'll help you with rewriting it into R. – raf18seb May 12 '20 at 09:32
  • @raf18seb almost (thanks for your support)! Your example works perfectly, since when you move the cursor on each single column, one can see the value and the category behind. But the second data series (the "negative-values" one ) should be exactly below the first data series (like in the screenshot example I linked in the post) and not "appended". So, imagine to shift the "Series 2" right below the "Series 1". Hope you was a bit more clear :) – Lorenzo May 12 '20 at 09:42
  • Ok, so you don't want to set separate categories on x-axis, but you just want to add "name" to the tooltip, right? Something like this? https://jsfiddle.net/BlackLabel/jbnf7k56/ – raf18seb May 12 '20 at 10:45
  • @raf18seb exactly like that! :) – Lorenzo May 12 '20 at 11:31
  • @raf18seb do you have any clue on how to achieve that in Shiny? – Lorenzo May 13 '20 at 09:57
  • Yes, I'm writing the answer ;) – raf18seb May 13 '20 at 11:07

1 Answers1

1

Highcharts displays the point's name in the tooltip by default. You just need to point the name value in your data. You can do it this way: top_growing <- data.frame(name = growing_seller, y = sales_yoy_growing)

This is the whole code:

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"
  )
raf18seb
  • 2,096
  • 1
  • 7
  • 19