Search code examples
rtreemap

How can I exclude small boxes in tree map?


I have a tree map code in R

treemap(df,
        index=c("Account.Name"),
        vSize = "X2017",
        type="index",
        palette = "Reds",
        title="Test tree",
        fontsize.title = 14 
)

Here this code generates tree map, but there are many very small boxes which have very small sum(default fun.aggregate) of "X2017" with respect to "Account.Name". Is there a way to exclude these small boxes like putting some limit or something ?


Solution

  • You can do the aggregation prior to creating the treemap. For example:

    library(dplyr)
    library(treemap)
    df_sum = df %>% group_by(Account.Name) %>% summarise(X2017 = sum(X2017)) %>% filter(X2017 > 10)
    treemap(df_sum,
            index=c("Account.Name"),
            vSize = "X2017",
            type="index",
            palette = "Reds",
            title="Test tree",
            fontsize.title = 14 
    )
    

    The above will first aggregate (sum) the X2017 field by Account Name and then keep only cases where X2017 > 10 (change this to your desired value). The rest is the same as your code but with the aggregated data frame as the input.