Tuesday, February 23, 2010

You know you are a Latex addict when...

You write -- for a dash(-) while taking notes on a piece of paper with a pen.

Friday, February 12, 2010

Plot layout in R

I recently needed to make a figure with two plots side-by-side. Plot 1 was to have a width 3 times that of plot 2. The layout feature in R seemed to be the answer. But, due to either lack of decent tutorials online or just plain bad luck in finding one, I found it rather difficult to understand how this layout function works. The usual help command help(layout) wasn't terribly helpful either. Here go the set of commands that really nailed it for me. Run them on your terminal to follow the rest of the blog.

nf <- layout(matrix(c(1,2),1,2),widths=c(1,1)); layout.show(nf)

Pretty straight forward isn't it? Now try,

nf <- layout(matrix(c(1,2),1,2),widths=c(3,1)); layout.show(nf)

Basically the matrix(c(1,2),1,2) is what contains the layout information. c(1,2) is simply the label of the plot in question. The 1,2 after that tells you the number if rows(1) and columns(2) in the layout. Now a little more complicated example,

nf <- layout(matrix(c(1,3,4,2,5,6,7,8),2,4),widths=c(1,1,1,5)); layout.show(nf)

Hope this helps.

Thursday, February 11, 2010

Colors in R

Hello World,
R is a pretty wicked statistical analysis tool with great resources for plotting data. I use it on a regular basis and I'll use this blog to document notable finds along the way. This will hopefully help me find answers to previously encountered problems by taking a peek at the blog rather than fishing through my sea of bookmarks. Here is a short comment on colors in R.

colors() gives a list of all the available colors in R. It looks like this:
[1] "white" "aliceblue" "antiquewhite"
[4] "antiquewhite1" "antiquewhite2" "antiquewhite3"
[7] "antiquewhite4" "aquamarine" "aquamarine1"
[10] "aquamarine2" "aquamarine3" "aquamarine4"
.
.
[646] "wheat" "wheat1" "wheat2"
[649] "wheat3" "wheat4" "whitesmoke"
[652] "yellow" "yellow1" "yellow2"
[655] "yellow3" "yellow4" "yellowgreen"

The way to select a particular color is:
plot(x,y,col=color()[646])
or
plot(x,y,col="wheat")

Ciao!