[R] There must be a better way to do this

David Perlman dperlman at wisc.edu
Tue May 8 19:59:12 CEST 2012


I made this rather cool plot which I am quite pleased with:
http://brainimaging.waisman.wisc.edu/~perlman/data/BeeswarmLinesDemo.pdf

However, I feel there must be a better way to do it than what I did.  I'm attaching the code to create it, which downloads the data by http so it should run for you if you have the current version of beeswarm installed (which was just updated today, incidentally).  It might also work with a non-current version of beeswarm.

The problem is that I jumped through all kinds of hoops to: 

a) get the subject numbers for each point associated with the point xy coordinates output by beeswarm.  The order of the points is not the same as the order in the input file; they are shuffled in a way that I think depends on the input formula.  The trick I used (ok, I hope you're sitting down when you read this) is to run beeswarm a second time with pwcol=Subj, so then the "col" column of the output becomes the subject numbers.  I know, horrible.  But I don't know how else to do it.  I feel like there is probably some logic to the way the cases were reordered by the formula, but I don't know how to work with that.

b) get the lines() function to pair the xy coordinates properly.  I did this by reshaping the whole thing into wide format, with separate columns for x.1 y.1 x.2 y.2, and then add a third pair of columns x.3 y.3 which is all NA, and then reshaping it back into long format.  Then the lines() function automatically does the right thing, but I feel like that was a horrible hack and there must be a smarter way to do it.


Thanks very much in advance for any help!


-dave----------------------------------------------------------------------
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says "What are you doing?" The neuroscientist says "Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!"




More information about the R-help mailing list