ramnathv / rMaps

Interactive Maps from R
http://rmaps.github.io
389 stars 194 forks source link

Missing Data #44

Open OFish opened 10 years ago

OFish commented 10 years ago

Hi, I'm using a data.frame that has missing values in the "Country" column. The code I run, gives me the following error:

crosslet(data=ARCTP53_EsoMut, id_field="Country", fields=c("Age", "Mut_rate")) Error in crosslet(data = ARCTP53_EsoMut, id_field = "Country", fields = c("Age", : unused arguments (id_field = "Country", fields = c("Age", "Mut_rate"))

and if I do this, then I get the following message:

ichoropleth(Age~Country, data=ARCTP53_EsoMut) Error in quantile.default(fml$left, seq(0, 1, 1/ncuts)) : missing values and NaN's not allowed if 'na.rm' is FALSE

So I tried doing this, which gives me the same error message.

ichoropleth(Age~Country, data=ARCTP53_EsoMut, na.rm=TRUE) Error in quantile.default(fml$left, seq(0, 1, 1/ncuts)) : missing values and NaN's not allowed if 'na.rm' is FALSE

What am I missing?

Cheers,

O.

bhtucker commented 10 years ago

Hey @OFish,

I think the na.rm error is being produced by the quantile function being called as part of ichoropleth. Hence, you can't solve this just by adding na.rm=TRUE to the ichoropleth call.

Some things don't work correctly with missing data. If you're ok with na.rm, perhaps just clean up the data frame itself, or better, make a clean version to use here.

I encountered the same issue and went with this, which I found acceptable for my data:

zipdat3$value[is.na(zipdat3$value)] <- 0

with zipdat3 being a modification of zipdat2, a modification of zipdat, due to taking destructive actions like setting things to zero.

Also, this seems like more of a stackoverflow question than an rMaps issue, but perhaps this error should be handled into something that doesn't invite people to try passing na.rm=TRUE.

ramnathv commented 10 years ago

Good point @bhtucker. I will modify the code so that a more informative error message is thrown.

Ankit-DA commented 10 years ago

Hi Ramnath,

I was trying to use crosslet function from rMaps package and got the following error :

data(web_index) crosslet(data=web_index,id_field="country",fields=c("web_index","universal_access"))

Error in crosslet(data = web_index, id_field = "country", fields = c("web_index", : unused arguments (id_field = "country", fields = c("web_index", "universal_access"))

ekstroem commented 10 years ago

@Ankit-DA

Without hijacking this completely try using the code format shown on the first rMaps page:

library(rMaps)
crosslet(
  x = "country", 
  y = c("web_index", "universal_access", "impact_empowerment", "freedom_openness"),
  data = web_index
)

I had this running without an error (although I didn't look at the output).

ramnathv commented 10 years ago

@Ankit-DA The note by @ekstroem is correct. rMaps internally maps x to id_field and y to fields. So use x and y and it should work.

Ankit-DA commented 10 years ago

Thanks so much @ekstroem and @ramnathv . It is executing now without error, however I don't see the output in the output window of RStudio, probably something to do with the configuration setting of RStudio. Is there a way I could store the resultant output HTML in a file and host that file somewhere on another server ?

Thanks !

bhtucker commented 10 years ago

@Ankit-DA - Sounds like you may be looking for the save method; I haven't use rMaps for crosslet, but I imagine the syntax may resemble ichoropleth:

d1 <- ichoropleth(x~zipcode,data=sumdf,pal='Greens',ncuts=9,animate='tax_year',map="ESRG_nyczip")
d1$save('regcoeffs.html', cdn = TRUE)

This save method is inherited from rCharts in general; see page 9 here: https://media.readthedocs.org/pdf/rcharts/latest/rcharts.pdf

Ankit-DA commented 10 years ago

Thanks @bhtucker for your response, however, $save is giving an error . This is what I tried - d<-crosslet( x = "country", y = c("web_index", "universal_access", "impact_empowerment", "freedom_openness"), data = web_index ) d$save('regcoeffs.html', cdn = TRUE)

This is the Error I received

Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length