i tried to create a marimekko chart in R Highcharter, following this example :
http://jsfiddle.net/highcharts/h2np93k1/
I cannot seem to get the sortIndex of the treemap to work, my code is as follows:
parentid <- c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5)
sortIndex <- c(0, 1, 2, 3, 4, 0, 1, 2, 3, 4)
child <- c("Alpha", "Alpha", "Alpha", "Alpha", "Alpha", "Beta", "Beta", "Beta", "Beta", "Beta")
childid <- c(100, 100, 100, 100, 100, 200, 200, 200, 200, 200)
colorid <- c(100, 100, 100, 100, 100, 200, 200, 200, 200, 200)
parent <- c("Parent 1", "Parent 2", "Parent 3", "Parent 4", "Parent 5", "Parent 1", "Parent 2", "Parent 3", "Parent 4", "Parent 5")
value <- c(10, 60, 70, 20, 90, 50, 30, 10, 90, 10)
data <- data.frame(parentid, sortIndex, child, childid, colorid, parent, value)
hctreemap2(data, group_vars=c("parentid", "childid"),
size_var="value",
color_var="colorid",
layoutAlgorithm='stripes',
alternateStartingDirection = T,
stacking="percent",
levelIsConstant = F,
sortIndex=sortIndex,
levels = list(
list(level=1, dataLabels = list(enabled=T, align='left', verticalAlign='top'), borderWidth=3),
list(level=2, dataLabels = list(enabled=T))))
does anyone have any ideas?
I realize this question was several years ago, and Highcharter has changed since it was written.
This answer may not have worked in 2018, but it does work now.
At some point
hctreemap
andhctreemap2
were deprecated. The instructions from Highcharter are to usedata_to_hierarchical
to prepare the data and then use eitherhchart()
orhighchart()
to create the treemap. However, this method will strip thesortIndex
, so I don't think that's the route you would want to go.Instead, I prepared the data by formatting it as it is in the JS link you provided and then graphed it.
The data:
Now the data is ready for plotting.