wilkox / treemapify

🌳 Draw treemaps in ggplot2
http://wilkox.org/treemapify
213 stars 18 forks source link

Intra-subgroup border color #15

Closed KyleKing closed 6 years ago

KyleKing commented 6 years ago

Is it possible to modify the color of the intra-group border color (not the geom_treemap_subgroup_border)? I would like a color that has higher contrast than the default gray so it will be more visible on a projector display

original

I tried setting the colour parameter in the aes argument, but the lines become red instead.

ggplot(G20, aes(area = gdp_mil_usd, fill = hdi, label = country, subgroup = region,
            colour = "black")) +
  geom_treemap() +
  geom_treemap_subgroup_border(colour = "black")

new

I just started working with R, but does this snippet overwrite the color?

https://github.com/wilkox/treemapify/blob/c859bc30ecc4cf283248369898599a6451456e1d/R/geom_treemap.R#L143-L157

wilkox commented 6 years ago

Set colour = black in geom_treemap:

ggplot(G20, aes(area = gdp_mil_usd, fill = region, label = country)) +
  geom_treemap(colour = "black") +
  geom_treemap_text(grow = T, reflow = T, colour = "black")

treemap

Putting colour = "black" inside aes doesn't work because aes is for mapping plot aesthetics to data variables, not for setting plot aesthetics to a fixed value. If you map the colour aesthetic to a single string 'black' (or any string for that matter), it's as if you've created a new column in your input data frame that just contains the value 'black' for all rows, and mapped the colour aesthetic to this column. ggplot2 will draw the variable with the default colour scale, which happens to have that pale red colour as its first value, which is why in your example the lines were drawn red.

KyleKing commented 6 years ago

Thank you!!