Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Thursday, September 8, 2011

Computing for Statistical Genetics: nice R slides

Thomas Lumley and Ken Rice have made a very nice set of "Computing for Statistical Genetics" slides on R that they prepared for the European Institute in Statistical Genetics.  This set of slides is available here

Friday, July 31, 2009

Excellent slides on R

Here are some excellent slides on R (pdf), which were made by Dr. Thomas Lumley for a Two-day Tutorial in "R" Statistical Computing that he gave in February 2006. 
 
These are by far the best slides I've seen so far on R, with lots of very useful advice and insights into how to use R optimally. 

Creating TIFF files from pdfs

R easily creates graphic files in pdf format, but many journals require that one submit high-resolution TIFF files. Johanna figured out how to convert from pdf to TIFF:

ghostscript can be used to change between formats. '-r' option for how
may d.p.i you want. This is the command to write to file (you can also
write to X11 using ghostview). It is also possible to change to and from
many other formats.

The command used:

gs -q -dNOPAUSE -dBATCH -sDEVICE=tifflzw -r600 -sOutputFile=name.tiff
name.pdf

I think when using preview to change from pdf to tiff it automatically
puts the figure in 72 d.p.i.

This looks very nice in Word even if zooming more than 200%.

NOTES:
A) The 'tifflzw' option results in a compressed file that is much much smaller than the corresponding uncompressed tiff file. And it is a loss-less compression, so there is no loss of quality.

B) The 'tifflzw' option produces monochrome output. If you need LZW-compressed color TIFF files, you can do this, using a command from the libtiff library:

gs -q -dNOPAUSE -dBATCH -sDEVICE=tiff24nc -r600 -sOutputFile=figure4a.TIFF figure_4a.pdf
tiffcp -c lzw figure4a.TIFF figure4aLZW.TIFF

C) For some reason, importing pdf figures into Microsoft Word causes the figures to become fuzzy. To avoid this, convert your pdf figures to compressed TIFF and then import the TIFF files into Word.

D) When creating plots within R, one can directly create a TIFF file using the bitmap() or dev2bitmap() functions. For example, this command:

dev2bitmap(file="test.tiff",type="tifflzw",res=600)

copied the plot I had already drawn in the R graphics window to a 600 DPI TIFF file named "test.tiff".

Using R to reshape data

Sometimes marker data are sent to us in this format, where each row only contains one genotype for a particular marker and person: 
 
ID Marker A1 A2 
1 M1 1 2 
2 M1 2 2 
3 M1 2 2 
1 M2 1 1 
3 M2 1 2 
 
However, in order to put this marker data in LINKAGE-format, we need to reshape the data so that each row contains all the marker data for a specific person. This can easily be done using the ‘reshape’ command in R: 
 
 
> a < - read.table("marker.txt",header=T) 
> a 
ID Marker A1 A2 
1 1 M1 1 2 
2 2 M1 2 2 
3 3 M1 2 2 
4 1 M2 1 1 
5 3 M2 1 2 
> attach(a) 
> b < - reshape(a,idvar="ID",direction="wide",timevar="Marker") 
> b 
ID A1.M1 A2.M1 A1.M2 A2.M2 
1 1 1 2 1 1 
2 2 2 2 NA NA 
3 3 2 2 1 2 
 

About Me

My photo
Pittsburgh, PA, United States