Search code examples
rhighchartsr-highcharter

Parallelcoordinates in R-highcharter R


I want to know how to use the highcharter-package to create parallelplots. I already found an implementation in the MASS-package, but this doesn't look nice. It results in

d <- iris[,1:4]
MASS::parcoord(d)

enter image description here

Since I want to use the plot in ShinyApps, I need a nicer visualization. I prefer highcharts, so I want to use the highcharter-package. Under https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples//highcharts/demo/parallel-coordinates/ we can find a demo of how to put in the data into highcharts, but I don't know how to set up the hchart-function correctly. I think it should be something like

hc <- highcharter::hchart(chart = list(type="spline",parallelCoordinates=TRUE) ...

Some help would be really appreciated, thanks in advance.


Solution

  • library(highcharter)
    library(purrr)
    library(dplyr)
    
    series_lst <- 
      iris %>% 
      as_tibble() %>% 
      asplit(1) %>% 
      imap(~list(
        name = paste("observation", .y),
        data = as.numeric(.x[1:4]),
        color = "steelblue"
      ))
    
    hc <- 
      highchart() %>% 
      hc_chart(parallelCoordinates = TRUE, type = "spline") %>% 
      hc_xAxis(categories = names(iris)[1:4]) %>% 
      hc_add_series_list(series_lst)
    

    Created on 2021-06-07 by the reprex package (v2.0.0)

    enter image description here