wilkox / treemapify

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

Color aesthetics not showing up in legend? #47

Closed jjbuonocore closed 11 months ago

jjbuonocore commented 11 months ago

I'm having some trouble getting the color aesthetic to show up in the legend. Working with the G20 example:

`ggplot2::ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = region)) + geom_treemap()

works just fine`

1

ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = region, color = econ_classification)) + geom_treemap() + scale_color_manual(values = c("red", "black"))

color does not show up in the legend

color and fill

ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = region, color = econ_classification, linetype = econ_classification)) + geom_treemap() + scale_color_manual(values = c("red", "black")) + scale_linetype_manual(values = c(1,3)) + guides(color = guide_legend(override.aes = list(color = c("red", "black"))))

fill shows up in a legend, along with linetype, but color does not`

color fill linetype

wilkox commented 11 months ago

Thanks for reporting this @jjbuonocore! I've pushed a fix to the development version and this will be released on CRAN soon.

library(ggplot2)
library(treemapify)

ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = region, 
                         color = econ_classification)) +
  geom_treemap() +
  scale_color_manual(values = c("red", "black"))


ggplot(G20, ggplot2::aes(area = gdp_mil_usd, fill = region, 
                         color = econ_classification, 
                         linetype = econ_classification)) +
  geom_treemap() +
  scale_color_manual(values = c("red", "black")) +
  scale_linetype_manual(values = c(1,3)) +
  guides(color = guide_legend(override.aes = list(color = c("red", "black"))))

Created on 2023-09-30 with reprex v2.0.2