wilkox / treemapify

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

Error message when "area" aesthetic data contains 0 #17

Closed py closed 6 years ago

py commented 6 years ago

This is a minor nit, but I spent way longer than I should have troubleshooting the error message.

The code below will recreate the error I experienced:

ggplot(G20, aes(area = gdp_mil_usd, fill = hdi)) +
  geom_treemap()

G20[1, "gdp_mil_usd"] <- 0

ggplot(G20, aes(area = gdp_mil_usd, fill = hdi)) +
  geom_treemap()

Running the last ggplot above will give you the error:

Error in if (aspectRatio > lastAspectRatio) { : 
  missing value where TRUE/FALSE needed

It turns out that I had a 0 value in the data I mapped to the area aesthetic, which led to a 0 or ∞ in the aspectRatio calculation. It might help to add a test to ensure all values of that aesthetic mapping are > 0 and an error message similar to "Data mapped to area aesthetic contains a 0. Please remove rows that contain 0 or choose another area variable.".

Just a suggestion - thanks for creating this great package.

wilkox commented 6 years ago

Thanks for the report @py! Fixed in 9d0cb3e v2.3.2.9002