Issue 8: TreeMap doesn't give error for 0s, but doesn't show plot
Status:  Done
Owner: ----
Closed:  Aug 2011
Reported by tomhi...@gmail.com, Aug 5, 2011
What is the expected output? What do you see instead?

Creating a treemap with NAs in the sizevar column brings up an error, but 0s don't. However when the plot appears in the browser, it is empty.

What version of the product are you using? On what operating system?

googleVis_0.2.8 RJSONIO_0.8-2 
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

Please provide any additional information below.

Best case scenario is the plot automatically removes 0s with a warning. Second best case is an error message.
Aug 9, 2011
Project Member #1 markus.g...@googlemail.com
This behaviour is as expected. NAs give an error message, while 0 are accepted but of course show an area of size 0.
Status: Invalid
Aug 9, 2011
#2 tomhi...@gmail.com
Sorry I wasn't so clear. And I see you are correct when I make a small treemap it behaves as you say. But for my large treemap, if any 0s are included in the data.frame, it isn't that the one row with the 0 doesn't display, the entire graphic doesn't display. 

For example this code works fine:

load('d:/delete/treemap.Rdata')
t8 <- t8[t8$y2010!=0,]	
ta <- gvisTreeMap(t8, idvar='id', parentvar='parent', sizevar='y2010', colorvar='diff', 
	options=list(width=1200, height=800, maxDepth=1, showScale=TRUE))

plot(ta)

But if I omit the second line, I get a blank plot. 

load('d:/delete/treemap.Rdata')
# t8 <- t8[t8$y2010!=0,]	
ta <- gvisTreeMap(t8, idvar='id', parentvar='parent', sizevar='y2010', colorvar='diff', 
	options=list(width=1200, height=800, maxDepth=1, showScale=TRUE))

plot(ta)


I hope this is useful. I find this package an excellent addition to R.

I've attached my t8 data, if you would like to try and replicate my results.

Thanks
treemap.Rdata
29.0 KB   Download
Aug 9, 2011
Project Member #3 markus.g...@googlemail.com
Thanks for the data set and your lines of code. 
I can replicate your problem now.

I believe the issue is caused by the Inf/-Inf values in your data set.
It appears that you calculated the relative difference without checking for division by zero.
Hence, I tried the following with an ifelse statement, which seems to cure your problem:

myt=t8
## recalculate the relative differences
myt$diff=with(t8, ifelse(y2009>0, (y2010/y2009 - 1)*100, NA))
p=gvisTreeMap(myt, 'id', 'parent','y2010', 'diff')
plot(p) ## displays a chart

## and I tried also

x=myt[myt$y2010!=0,]
p=gvisTreeMap(x, 'id', 'parent','y2010', 'diff')
plot(p) ## displays a chart as well

Arguably a warning could be shown if the data set includes Inf/-Inf values.



Status: Accepted
Aug 9, 2011
#4 tomhi...@gmail.com
Excellent! Thank you very much for the tip.

On Tue, Aug 9, 2011 at 2:02 PM,
<google-motion-charts-with-r@googlecode.com>wrote:
Aug 28, 2011
Project Member #5 markus.g...@googlemail.com
The warning section of the help file has been updated to highlight this potential issue.
Status: Done