Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to make squarified layouts do rows first then columns? #43

Open
slyrus opened this issue Oct 24, 2020 · 2 comments
Open

Comments

@slyrus
Copy link

slyrus commented Oct 24, 2020

I almost have the layout I'm looking for, with 4 groups in my treemap, but no matter which corner I start from, I always get the x-axis split into two equally, but not the y-axis.

e.g.:

  local({
      start <- "topleft"
      layout <- "squarified"
      tibble::tibble(A = c(1,1,0,0),
                     B = c(0,1,1,0),
                     pct = c(0.69, 0.14, 0.06, 0.11)) %>%
          dplyr::mutate(label = paste("A=", A, "\n", "B=", B, sep="")) %>%
          ggplot2::ggplot(ggplot2::aes(area = pct,
                                       subgroup = A,
                                       subgroup2 = B,
                                       label = label)) +
          treemapify::geom_treemap(start = start, layout = layout) +
          treemapify::geom_treemap_text(start = start)
  })

What I'm looking for is the A=1,B=0 and A=1,B=1 groups placed along the top in boxes of equal height. I can get equal width, but not equal height and starting from different corners or reversing the subgroups doesn't seem to help.

@wilkox
Copy link
Owner

wilkox commented Oct 24, 2020

Unfortunately there's no way to force a layout like this with the current set of layout algorithms. The squarified, srow and scol layouts are all variants on an algorithm that prioritises drawing tiles with an aspect ratio as close to one as possible, without any regard to how many tiles or subgroups end up in a row or column. I suppose I could add an algorithm that gives each subgroup its own row or column, and then draws the tiles within that subgroup as single row or column; I'm curious to know what the use case would be for this though?

@slyrus
Copy link
Author

slyrus commented Oct 25, 2020

It's not a major need, I just, conceptually, like the look of a solid row on top, rather than a solid column on the left. 4 regions may be something of a degenerate case and I can imagine this might be difficult to support in general, but the results from the existing algorithm are almost exactly what i want, I just want it rotated 90 degrees. coord_flip doesn't work as a workaround. Anyway, great package. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants