Closed fmgarciadiaz closed 5 years ago
Hi Fernandez, thanks for reporting this. The layout algorithm did change a little in v2.5.0 but not in a way that should produce tiles with bad aspect ratios. Could you post an example (preferably as a reprex) that produces thin tiles so I can check if it's a bug? Thanks!
Hi! Thanks for the feedback! I really like treemapify! See below both tree maps, one with 2.4.0 and the other one with 2.5.0 Both made with the same code:
ggplot( data = Simil_ARG , aes(area = M , fill = region, subgroup = region)) +
#label = country %+% "\n" %+% format((M/1000000000), digits = 0) %+% " USD MM") ) +
geom_treemap(color = "white", size = 1 , alpha = 1) +
geom_treemap_text(aes(label = country) , color = "black", size = 10 , family = font_rc, fontface = "bold") +
geom_treemap_text(aes(label = format((M/1000000000), digits = 0, trim = TRUE) %+% " USD MM") ,
color = "black", size = 8 , place = "topleft", family = font_rc_light , padding.y = grid::unit(13, "points")) +
geom_treemap_subgroup_border(color = "white", size = 2) +
geom_treemap_subgroup_text(color = "darkgray", grow = FALSE , size = 15, , place = "bottomleft", family = font_rc, fontface = "bold", alpha = 0.7) +
scale_fill_brewer(palette = "Set1", guide = FALSE) +
scale_color_brewer(palette = "Set1", guide = FALSE)
Sorry I can't use reprex because it's a very large data file.
v 2.4.0
v 2.5.0 <- Notice the "larger" tiles, for example, in South Asia.
Thanks!!!
Thanks Fernando (sorry for getting your name wrong in my first reply)! I think this is related to the change from column-first to row-first tile placement in v2.5.0. This was intended to produce tiles with better aspect ratios for horizontal text, but as you’ve found the layout might be aesthetically worse for some datasets.
I’m planning to add arguments that allow users to select between column- and row-first layouts, and to change the corner from which tile placement starts (see #30). This should at least give you the option of trying an alternative layout if the default is unappealing. I’ll update this issue when I’ve added these features.
That will be great!
Thanks for your feedback wilkox, treemapify
rocks!
The latest development version v2.5.0.9004 adds a layout
argument that lets you choose a row-first (layout = "srow"
, the default) or column-first (layout = "scol"
) squarified layout. You can install the development version with devtools::install_github("wilkox/treemapify")
. Does this solve your issue?
Almost! Now the subgroups layout is the same as before, but some tiles seem very "tall" as compared with 2.4.0.
Here's the code
# GRAFICO EXPOS ARGENTINA
g <- ggplot(data = expos , aes(area = export_value/1000000 , fill = factor(rubro, levels = c("CyE","MOA","MOI","PP"),
labels = c("Combustibles y EnergÃa", "Manufacturas Origen Agropecuario",
"Manufacturas Origen Industrial","Productos Primarios")),
subgroup = rubro2)) +
treemapify::geom_treemap(color = "white", size = 1 , alpha = 1, fixed = FALSE, layout = "scol") +
geom_treemap_text(aes(label = ncm2_desc) , color = "black", size = 8 , family = font_rc, grow = FALSE, alpha = 0.8,layout = "scol") +
geom_treemap_text(aes(label = "USD " %+% formatC((export_value/1000000), format = "f", digits = 0, big.mark = ".") %+% " MM") ,
color = "black", size = 8 , place = "topleft", family = font_rc_light , padding.y = grid::unit(13, "points"), layout = "scol") +
geom_treemap_text(aes(label = formatC((export_value/sum(export_value)*100), format = "f", digits = 1) %+% "%") ,
color = "black", size = 8 , place = "topleft", family = font_rc_light , fontface = "italic", padding.y = grid::unit(21, "points"),layout = "scol") +
geom_treemap_subgroup_border(color = "white", size = 2,layout = "scol") +
geom_treemap_subgroup_text(color = "white", grow = FALSE , size = 20, place = "bottomleft", family = font_rc, fontface = "bold", alpha = 0.7,layout = "scol") +
scale_fill_manual(values = Paleta, guide = FALSE) +
theme_ipsum_rc()
I've just added a new default layout, 'sopt', in the development version v2.5.0.9005. Can you try it out and see if it improves your plot?
Thanks Wilkox and sorry for the delay! Here are the results:
layout = "sopt"
(looks nice, although something different from the original layout - see below)layout = "scol"
layout = "srow"
Thanks Fernando. I agree that it still doesn't look as good as the old algorithm. I'll do some more digging through the old code to try to figure out why!
@fmgarciadiaz Sorry it's taken me so long to get around to this, I've been flat out for the last month with exams.
I think I've finally found the problem: I introduced a bug in 2.5.0 whereby tiles within subgroups would be laid out as if the shape of the subgroup was a perfect square, even if it was actually rectangular. I've fixed the bug in 4c66322. Please try it out and let me know if it works for you. If this does think the problem, I'll probably remove the new 'scol' and 'srow' layouts before releasing on CRAN as I don't think they're very useful.
Thank you so much for your patience and for helping me find this issue!
Dear wilkox i'll try it out and let you know. Thanks to you for this amazing package =)
Dear wilkox, the layout has been fixed for good! Great!!!!! =)
pd. Please note that geom_treemap_text is not showing when loading the development version for the first time. If I first try the last stable version, then install and load the development version, they show OK.
Somehow v2.4.0 tiles seem to look nicer than in v2.5.0. Version 2.5.0 treemap tiles look a lot "thiner" than previous versions, was that intended? Thanks!! =)