helgasoft / echarty

Minimal R/Shiny Interface to ECharts.js
https://helgasoft.github.io/echarty/
87 stars 3 forks source link

charts morphing #17

Closed helgasoft closed 2 years ago

helgasoft commented 2 years ago

How to duplicate ECharts morphing demo of smooth transition to aggregated data chart, question asked here. Solution is data preparation in R, then visualization.

library(dplyr)
mc <- mtcars |> filter(cyl<8)
datt <- function(idx) { return(mc[mc$cyl==idx,]$hp) }
colors <- c("blue","red")

oscatter <- list(
  title= list(subtext='mouseover points to morph'),
  xAxis= list(scale=TRUE),
  yAxis= list(scale=TRUE), color= colors,
  series=list(
    list(type='scatter', id=4, dataGroupId=4, data= datt(4),
         universalTransition= list(enabled= TRUE)),
    list(type='scatter', id=6, dataGroupId=6, data= datt(6),
         universalTransition= list(enabled=TRUE)) 
  )
)
obar <- list(
  title= list(text= 'Average'),
  xAxis= list(type= 'category', data= list('cyl4', 'cyl6')),
  yAxis= list(show= TRUE), color= colors,
  series= list(list(
    type= 'bar', id= 'average', colorBy= 'data',
    data= list(
      list(value= mean(datt(4)), groupId=4),
      list(value= mean(datt(6)), groupId=6)),
    universalTransition=list(enabled= TRUE, 
                             seriesKey=c('4', '6'))
  ))
)

# remotes::install_github('helgasoft/echarty')  # get latest
library(echarty) 
ec.util(cmd='morph', oscatter, obar)

morf

rdatasculptor commented 2 years ago

Brilliant!