Presentation is loading. Please wait.

Presentation is loading. Please wait.

BINF634 - Perl and R1 BINF634 Perl and R. BINF634 - Perl and R2 Some R References The R Book by Michael J. Crawley The R Book Statistics An Introduction.

Similar presentations


Presentation on theme: "BINF634 - Perl and R1 BINF634 Perl and R. BINF634 - Perl and R2 Some R References The R Book by Michael J. Crawley The R Book Statistics An Introduction."— Presentation transcript:

1 BINF634 - Perl and R1 BINF634 Perl and R

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

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

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

5 > 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))) R as a Calculator 5BINF634 - Perl and R

6 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

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

8 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 Getting Help 8BINF634 - Perl and R

9 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

10 BINF634 - Perl and R10 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" Vectors

11 BINF634 - Perl and R11 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) Graphics in R

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

13 BINF634 - Perl and R13 obarplot - Creates a Bar Plot oboxplot - Creates Side-by-Side Boxplots ohist - Creates a Histogram odotchart - Creates a Dot Chart opie - Creates a Pie Chart oNote - These commands along with the commands on the next several slides are all high-level graphics calls. Plotting Functions That Are Useful for One-dimensional Data

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

15 BINF634 - Perl and R15 File-Print Menu oStarting Printing Graphics Device oPostscript - Postscript oPdf oPictex - Latex oWindows - Metafile opng - PNG bitmap device oJpeg - JPEG bitmap device oBmp - BMP bitmap device oXfig - Device for XFIG graphics file format Printing Graphics

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

17 BINF634 - Perl and R17 #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) Alternative Screen Printing Approach

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, heig ht=500, pointsize=1)`); $R->run(q`plot(c(1, 5, 10), type = "l")`); $R->run(q`dev.off()`); BINF634 - Perl and R18

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 R19

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 R20


Download ppt "BINF634 - Perl and R1 BINF634 Perl and R. BINF634 - Perl and R2 Some R References The R Book by Michael J. Crawley The R Book Statistics An Introduction."

Similar presentations


Ads by Google