0
votes

I want to show the distribution of windturbine's events using Highcharts.

My X-axis won't display its values entirely well. I found that when I have only one event defined for one year, it mucks up the vizualisation.

However when I have multiple events on several years, it goes smooth. I don't know if the code misses one option or if I should use another function to display my results.

Below is the code and the associated results.  mpgg_EX highchart stackbar

library(highcharter)
library(dplyr)
library(highcharter)
    mpgg_EX <- data.frame("Country" = c("Belux","Belux","Belux","Belux","Belux"), "WT_Manufacturer" = c("bubble","bubble","bubble","bubble","fever"), "Start_Event_Date" = c("2013", "2014","2015","2016","2013"),"BLA"=c(0,0,0,0,0),"ELEC"=c(1,0,0,0,0),"MECA"=c(1,1,1,1,1),"OTH"=c(0,0,0,0,0),"PWEL"=c(0,1,0,0,0),"VAR"=c(1,0,0,0,0),stringsAsFactors = FALSE)

       categories_grouped_EX <- mpgg_EX %>% 
        group_by(name = WT_Manufacturer) %>% 
        do(categories = .$Start_Event_Date) %>% 
        list_parse()
    categories_grouped_EX<- lapply(categories_grouped_EX, function(x) x[!is.na(x)])

      hc_indispo_EX <- highchart() %>%
        hc_chart(type = "column") %>%
        hc_colors("#fc5421") %>%   
        hc_title(text = "Unavailability Manufacturer Example") %>%
        hc_xAxis(title = "Suppliers"
                ,type = "category"
                ,categories = categories_grouped_EX
                 ) %>%
        hc_legend(layout = "vertical", verticalAlign = "bottom",align = "right", valueDecimals = 0, reversed = TRUE) %>% 

         hc_plotOptions(
          series = list(
            cropThreshold = 1000,
            stacking = "normal",
            borderWidth = 0,
            grouping = TRUE,
            dataLabels = list(enabled = FALSE)
          )
        ) %>%
            hc_add_series(
          data = mpgg_EX,
          type = "column",
          name = "MECA",
          hcaes(x = Start_Event_Date,
                y = MECA)
         ) %>%
        hc_tooltip(formatter = JS("function(){
           var point = this.point;
           s = '<b>' + this.series.name + '</b>' + ' :' + Highcharts.numberFormat(this.y,0)  + '<br/>';
            s += '<b>' + 'Total : ' + '</b>' + Highcharts.numberFormat(point.stackTotal,0)  + '<br/>';
           return (s)}"
           ))

      hc_indispo_EX
Maybe if you reduced the code to only the part that is reproducing your problem it would be easier to help you. The code you gave with your question is way to much code for me to read and try to understand. Check here to see how to make a minimal reproducible example.dario
I removed the functions, I think I put the minimum code!linoazone
@linoazone - this appears to be an issue on github. Try do(categories = as.list(.$Start_Event_Date)) in grouping as a workaroundBen
Hi. I have some errors when trying to run your code in RStudio: "Error in group_by(., name = WT_Manufacturer) : could not find function "group_by"" and others. Could you provide all the code (with packages) needed to run your chart?raf18seb
Hello @raf18seb , I have added library(dplyr) in the codelinoazone