Tuesday, September 01, 2009

R for a PERL nut

So for days I've been trying to make sense of R. I've been told by many people that although the learning curve is "steep" its very useful in the "long run". B.S.

The learning curve wouldnt be that steep if there was some decent documentation with simple instructions. After about 3 weeks, I've finally figured out how to generate a simple scatterplot. Even perl with its primitive GD and chart options wouldnt have taken longer than 4 hours to figure out. What a waste of time! But I guess in the "long run" figuring out how to actually do it maybe useful.

I thought I'd just post what I'd done for the benefit anyone else in a similar predicament.

1. Start R client by typing : R
2. read in tab delimited file, substitute , I just needed the first 39K rows hence nrow, you have to read the function into a variable (my case 'd') otherwise it prints to stdout, ie, the screen:
d=read.table ('',sep='\t',nrow=39450)
3. Check if all rows read in using (remember d is your variable):
dim(d)
4. If your file doesnt have headers as is the case with mine, your columns will be called V1, V2, V3, etc. To generate a scatterplot (this is the default graph type in R):
plot (d$V3,d$V2)
remember d is the variable for the matrix of values, you prefix with $ to access any of the columns. I wanted V3 on the x axis , so I specified that first.
5. Quit from R:
q()
6. You should be asked if you wanted to save images from your session say yes.
7. File is stored by default under R.pdf

I haven't figured out how you specify an output file name or if theres an easy way to generate and concatenate multiple plots. But hey, there should always be a start! Even if its with P-I-T-A "R" (just my personal sentiment, for now at least).

2 comments:

Anonymous said...

Read:

http://freshmeat.net/articles/creating-charts-and-graphs-with-gnu-r

Veena said...

Thanks, that was a good one. Now, if only I can get bioinformatics modules like Limma to work!