mbojan / alluvial

Alluvial diagrams
Other
139 stars 26 forks source link

Character vectors in data trigger warnings and no plot produced #1

Closed zief0002 closed 10 years ago

zief0002 commented 10 years ago

Hi

I am running R version 3.0.3 (2014-03-06) -- "Warm Puppy" on Mas OS X Mavericks. After issuing the alluvial function I was greeted with this. Just thought you may want to know. Thanks Andy

Warning message: In diff(as.numeric(d[o, i])) : NAs introduced by coercion Dec 31 17:59:59 CEHD-m1152336 R[71791] : Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API. This is a serious error and contributes to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

mbojan commented 10 years ago

Thanks. Can you send me some sort of micro-example that reproduces the problem?

zief0002 commented 10 years ago

Sure. I am pretty sure it was a result of having character vectors rather than factor vectors. Once I coerced the strings into factors then there was no problem. The code below will recreate the problem in the second alluvial plot if you omit the coercion before plotting.

The data I used is also attached.

It is a cool package. Thanks for putting it together. You can see the blog post I added the plot to at http://urbaneramblings.blogspot.com/

I will also write one for Citizen Statistician and in that post, I will likely write more about the R syntax. I will also link folks over to your page.

#######

nit = read.csv(file.choose(), stringsAsFactors = FALSE)

nit2 = nit[2:76, ]

##########

nit2$NCAA2 = factor(nit2$NCAA, labels = c("No Bid", "Tournament Bid")) nit2$NCAAresult = factor(nit2$NCAAresult, levels = c("No Bid", "Lost First Round", "Lost Second Round", "Lost Regional Semifinal", "Lost Regional Final", "Lost National Semifinal"), ordered = TRUE)

nit2$numTeams = ifelse(nit2$NumTeamsNCAAtourn == 8, 8, ifelse(nit2$NumTeamsNCAAtourn == 16, 16, ifelse(nit2$NumTeamsNCAAtourn < 64, 48, 68 ) ) )

nit2$numTeams = factor(nit2$numTeams)

only two variables: class and survival status

nit3 = aggregate(NCAA ~ NCAA2 + NCAAresult, data = nit2, length)

#######

library(alluvial)

alluvial(nit3[ , 1:2], freq = nit3$NCAA, xw = 0.0, alpha = 0.8, gap.width = 0.1, col = "steelblue", border = "white")

alluvial(nit2[ , c(20, 19, 7)], freq = length(nit2$NCAA), border = NA, hide = length(nit2$NCAA) < quantile(nit2$NCAA, .50), col = ifelse( nit2$NCAAresult != "No Bid", "#377eb8", "gray") )

On Wed, Apr 9, 2014 at 7:58 AM, Michał Bojanowski notifications@github.comwrote:

Thanks. Can you send me some sort of micro-example that reproduces the problem?

— Reply to this email directly or view it on GitHubhttps://github.com/mbojan/alluvial/issues/1#issuecomment-39960358 .

Andrew Zieffler, Ph.D. Educational Psychology University of Minnesota http://www.tc.umn.edu/~zief0002

mbojan commented 10 years ago

Thanks. Indeed, the function seems to trip over character vectors. I guess I'll fix it by converting them to factors internally.

mbojan commented 10 years ago

Fixed in 879b04: character vectors in data are now converted to factors.