1 / 20

BINF634 Perl and R

BINF634 Perl and R. Some R References. The R Book by Michael J. Crawley Statistics An Introduction using R by Michael J. Crawley Introductory Statistics with R (Statistics and Computing) by Peter Dalgaard R Graphics , Paul Murrell

Télécharger la présentation

BINF634 Perl and R

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BINF634 Perl and R BINF634 - Perl and R

  2. Some R References • The R Book by Michael J. Crawley • Statistics An Introduction using R by Michael J. Crawley • Introductory Statistics with R (Statistics and Computing) by Peter Dalgaard • R Graphics, Paul Murrell • Data Analysis and Graphics Using R, John Maindonald et al. • Using R for Introductory Statistics by John Verzani BINF634 - Perl and R

  3. Making it Go • Under Unix/LINUX Type R (or the appropriate path on your machine) • Under Windows Double click on the R icon BINF634 - Perl and R

  4. Making it Stop • Type > q() • q()is a function execution • Everything in R is a function • q merely returns a listing of the function BINF634 - Perl and R

  5. R as a Calculator > log2(32) [1] 5 > sqrt(2) [1] 1.414214 > seq(0, 5, length=6) [1] 0 1 2 3 4 5 > plot(sin(seq(0, 2*pi, length=100))) BINF634 - Perl and R

  6. Syntax • Everything that we type in R is an expression • We may have multiple expressions on each line separated by ; 2+3;4*5;6-9 • We use <- or = for making assignments b<-5+9 or b = 5+9 • R commands are case sensitive • The result of any expression is an object BINF634 - Perl and R

  7. Recalling Previous Commands • In WINDOWS/UNIX one may use thearrow up key or thehistory command under the menus • Given the history window then one can copy certain commands or else past them into the console window BINF634 - Perl and R

  8. Getting Help • In both environments we may use help(command name) ?command name > help("ls") > ? ls • We may also use methods(command name) • html-based help help.start() • For commands with multiple methods based on different object types BINF634 - Perl and R

  9. Assignments in R • Some Examples > cat<-45 > dog=66 > cat [1] 45 > dog [1] 66 > 77 -> rat > rat [1] 77 • Note = is used for specifying values in function calls BINF634 - Perl and R

  10. Vectors • A vector example > a<-c(1,2,3,4) > length(a) [1] 4 > a [1] 1 2 3 4 • An example with character strings > name<-c("Jeff","Solka") > name [1] "Jeff" "Solka“ > name[1] [1] "Jeff" BINF634 - Perl and R

  11. Graphics in R • win.graph() or in UNIX we say x11() • dev.list() - list currently opened graphics devices • dev.cur() - list identifier for the current graphics device • dev.off() - close the current graphics window • A simple plotting example > x<-rnorm(100) > y<-rnorm(100) > plot(x,y) BINF634 - Perl and R

  12. High-level Graphics Functions • win.graph(), x11() • All Examples of Calls to Launch Graphics Window • A simple example • > x = rnorm(100) • > win.graph() • > hist(x) BINF634 - Perl and R

  13. Plotting Functions That Are Useful for One-dimensional Data • barplot- Creates a Bar Plot • boxplot- Creates Side-by-Side Boxplots • hist- Creates a Histogram • dotchart- Creates a Dot Chart • pie- Creates a Pie Chart • Note - These commands along with the commands on the next several slides are all high-level graphics calls. BINF634 - Perl and R

  14. A Simple Pie Chart > data = c(10,20,30) > labels = c("a", "b", "c") > pie(data,labels=labels) BINF634 - Perl and R

  15. Printing Graphics • File-Print Menu • Starting Printing Graphics Device • Postscript - Postscript • Pdf • Pictex - Latex • Windows - Metafile • png - PNG bitmap device • Jpeg - JPEG bitmap device • Bmp - BMP bitmap device • Xfig - Device for XFIGgraphics file format BINF634 - Perl and R

  16. Capturing Graphics to a jpeg File jpeg(file=“junk.jpg”) plot(x,y,pch=“*”) dev.off() BINF634 - Perl and R

  17. Alternative Screen Printing Approach #plot in an x11 or wingraph window and then write the output to a file > dev.print(bmp, file="myplot.bmp", width=1024, height=768) BINF634 - Perl and R

  18. Call R from Perl use Statistics::R; # Create a communication bridge with R and start R my $R = Statistics::R->new(); # Run simple R commands my $output_file = "file.ps"; $R->run(qq`postscript("$output_file" , horizontal=FALSE , width=500 , height=500 , pointsize=1)`); $R->run(q`plot(c(1, 5, 10), type = "l")`); $R->run(q`dev.off()`); BINF634 - Perl and R

  19. q and qq • q acts the same as single quotes so we do not have variable interpolation and it ignores single quotes • qq used to interpolate variables but to ignore double quotes BINF634 - Perl and R

  20. Communicating With R use Statistics::R; # Create a communication bridge with R and start R my $R = Statistics::R->new(); # Pass and retrieve data (scalars or arrays) my $input_value = 1; $R->set('x', $input_value); $R->run(q`y <- x^2`); my $output_value = $R->get('y'); print "y = $output_value\n"; $R->stop(); BINF634 - Perl and R

More Related