Treemap subplot in PlotlyJS

I wanted to use a treemap in PlotlyJS. There is no method like this, so I create that by hand.

fieldsa = Dict{Symbol,Any}(:type => "treemap",
   :labels => ["a", "A"],
   :parents => ["", ""],
   :values => [1, 10],
   :textinfo => "label+value+percent entry")
fieldsb = Dict{Symbol,Any}(:type => "treemap",
   :labels => ["b", "B"],
   :parents => ["", ""],
   :values => [5, 3],
   :textinfo => "label+value+percent entry")

I would like to have a layout with 2 rows - to plot the 2 treemaps one below the other.
So I tried this:

p1 = PlotlyJS.plot([ GenericTrace("treemap", fieldsa) ], Layout())
p2 = PlotlyJS.plot([ GenericTrace("treemap", fieldsb) ], Layout())
p = [p1; p2]

No luck, only one treemap is displayed.

Also this one shows only one treemap. But it looks like there is a empty row…

layout = Layout(grid=attr(rows=2, columns=1))
plot([ GenericTrace("treemap", fieldsa), GenericTrace("treemap", fieldsb) ], layout)

Any idea why how to make it work? I suspect that it doesn’t work because the treemap is not known to PlotlyJS package…

Thanks a lot!


Note that it works with e.g. scatter

p1 = PlotlyJS.plot([scatter(x = [1, 2], y = [10, 20])], Layout())
p2 = PlotlyJS.plot([scatter(x = [1, 2], y = [5, 18])], Layout())
p = [p1; p2]   # shows 2 plots in one pane

Treemaps are special charts, and when you insert them as subplots, you have to
set domain_x, domain_y as subintervals in [0,1], to inform plotly.js where to locate
each treemap window within the unit square [0,1] x[0,1] (the plotting window).
Here is an example where in each subplot I inserted the same tree (with data from Treemap Charts | Python | Plotly):

using PlotlyJS
tree1= treemap(
    labels = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"],
    root_color="lightgrey",
    domain_x = [0,1],
    domain_y = [0,0.48]
   )

tree2= treemap(
    labels = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"],
    root_color="lightgrey",
    domain_x =[0,1],
    domain_y = [0.52, 1]
   )
data= [tree1, tree2]
layout=Layout(width=700, height=500)
pl = plot(data, layout)

Thank you @empet, this really solves my problem. The working code looks like this:

fieldsa = Dict{Symbol,Any}(:type => "treemap",
   :labels => ["a", "A"],
   :parents => ["", ""],
   :values => [1, 10],
   :textinfo => "label+value+percent entry",
   :domain => Dict{Symbol,Any}(:x => [0,1], :y => [0,0.48]))
fieldsb = Dict{Symbol,Any}(:type => "treemap",
   :labels => ["b", "B"],
   :parents => ["", ""],
   :values => [5, 3],
   :textinfo => "label+value+percent entry",
   :domain => Dict{Symbol,Any}(:x => [0,1], :y => [0.52,1]))
p1 = PlotlyJS.plot([ GenericTrace("treemap", fieldsa) ], Layout())
p2 = PlotlyJS.plot([ GenericTrace("treemap", fieldsb) ], Layout())
p = [p1; p2]

Is there any other chart that is special like treemap?

I was also wondering why I don’t have treemap function defined. But I was at version v0.14.1 and I see, 0.18 is available… Honestly, I did’t succeed in installing this version because add PlotlyJS gives me only 0.15, so I can’t check.

Sunburst chart, that also represents a tree, needs setting the attribute domain for x and y , when included in a subplot.

1 Like