Thursday, 29 October 2020

Legend duplicating identical names in higcharts for R

I've made a timeline chart in highcharter, the R api for Highcharter. I want it to display a legend item for each of the color segments, but only once. The way it's rendering now, it repeats for every name. I've found that you can "link" series in higcharts in JavaScript but haven't figured out how to that in R.

Here's what I'm doing:

df %>% 
    hchart("timeline", hcaes(x = date,
                           label = paste0("<b>", company, "</b>"),
                           color = segment,
                           name = paste0("<i>", segment, "</i>")),
         dataLabels = list(allowOverlap = FALSE),
         linkedTo = "color",
         showInLegend = TRUE) %>% 
  hc_yAxis(visible = FALSE) %>% 
  hc_xAxis(type = "datetime")

And some data:

df <- structure(list(date = c(1446681600000, 1420070400000, 1.419984e+12, 
1356998400000, 1348531200000, 1310342400000, 1.238544e+12, 1.238544e+12, 
1.222992e+12, 1187913600000), company = c("SymphonyAI - Ayasdi", 
"Longbow (Orlando)", "CFD Research", "DB CyberTech", "M5 Network Security", 
"Daylight Solutions", "Sonoma Photonics", "Swift Engineering", 
"3001 International", "Scaled Composites"), segment = c("Comms & Cyber", 
"Not JADO Related", "Training & Simulation", "Comms & Cyber", 
"Comms & Cyber", "Not JADO Related", "Not JADO Related", "Not JADO Related", 
"Not JADO Related", "Not JADO Related")), row.names = c(NA, -10L
), class = c("tbl_df", "tbl", "data.frame"))

This is what it looks like now: enter image description here

I certainly don't need the same categories to keep repeating, right?



from Legend duplicating identical names in higcharts for R

No comments:

Post a Comment