library(dplyr)
ds <- iris |> relocate(Species) |>
ec.data(format= 'boxplot', jitter= 0.1, layout= 'v')
ec.init(
dataset= ds$dataset, series= ds$series, xAxis= ds$xAxis, yAxis= ds$yAxis,
legend= list(show= TRUE), tooltip= list(show= TRUE)
)
hc <- hclust(dist(USArrests), "complete")
ec.init(preset= FALSE,
series= list(list(
type= 'tree', orient= 'TB', roam= TRUE, initialTreeDepth= -1,
data= ec.data(hc, format='dendrogram'),
# layout= 'radial', symbolSize= ec.clmn(scale= 0.33),
## exclude added labels like 'pXX', leaving only the originals
label= list(formatter= htmlwidgets::JS(
"function(n) { out= /p\\d+/.test(n.name) ? '' : n.name; return out;}"))
))
)
# build required pathString,value and optional itemStyle columns
df <- as.data.frame(Titanic) |> rename(value= Freq) |> mutate(
pathString= paste('Titanic\nSurvival', Survived, Age, Sex, Class, sep='/'),
itemStyle= case_when(Survived=='Yes' ~"color='green'", TRUE ~"color='LightSalmon'")) |>
select(pathString, value, itemStyle)
ec.init(
series= list(list(
data= ec.data(df, format='treeTT'),
type= 'tree', symbolSize= ec.clmn("(x) => {return Math.log(x)*10}")
)),
tooltip= list(formatter= ec.clmn('%@%@%','value','pct'))
)
Run the code above in your browser using DataLab