How to swap two levels in a tree diagram


#1

For example: I have a tree, such as the following:

Root node: Total
Level 1: Value vs Mainstream (2 nodes)
Level 2: Bottles vs Can (2 nodes)
There is a Chi Square statistics associated with this tree.

What is the best way to swap the two levels? Do you know any R packages built for this purpose?

For example, if they swap Level 1 and Level 2, the updated tree would be:

Root node: Total
Level 1: Bottles vs Can (2 nodes)
Level 2: Value vs Mainstream (2 nodes)

Thank you!