Collapse heatmap to phylum level and genus level separately

Hi, i need support in collapsing my heatmap to phylum level. I am following the tutorial of @jbisanz (great job). I am new to R, I successfully made the heatmap but would love to collapse it into phylum and have only phylum genera at the y axis. i also want to make the same for Genus level. please, I tried to massage the code to get that but had several errors. any help will be appreciated. Thank you.

This is my plot