tush1r / google-motion-charts-with-r

Automatically exported from code.google.com/p/google-motion-charts-with-r
0 stars 0 forks source link

TreeMap doesn't give error for 0s, but doesn't show plot #8

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by tomhi...@gmail.com on 5 Aug 2011 at 4:03

GoogleCodeExporter commented 9 years ago
This behaviour is as expected. NAs give an error message, while 0 are accepted 
but of course show an area of size 0.

Original comment by markus.g...@googlemail.com on 9 Aug 2011 at 7:38

GoogleCodeExporter commented 9 years ago
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

Original comment by tomhi...@gmail.com on 9 Aug 2011 at 8:57

Attachments:

GoogleCodeExporter commented 9 years ago
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.

Original comment by markus.g...@googlemail.com on 9 Aug 2011 at 12:01

GoogleCodeExporter commented 9 years ago
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:

Original comment by tomhi...@gmail.com on 9 Aug 2011 at 12:28

GoogleCodeExporter commented 9 years ago
The warning section of the help file has been updated to highlight this 
potential issue.

Original comment by markus.g...@googlemail.com on 28 Aug 2011 at 6:14