Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012.

Similar presentations


Presentation on theme: "An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012."— Presentation transcript:

1 An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012

2 R graphics – Nice and Simple R has powerful graphics facilities for the production of publication-quality diagrams and plots. Can produce traditional plots as well as grid graphics. Great reference: Murrell P., R Graphics

3

4 Topics for today Histograms Plot, points, lines, legend, xlab, ylab, main, xlim, ylim, pch, lty, lwd. Scatterplot matrix Individual profiles 3D graphs

5 Data Puromycin – Before and After

6 R code Data available in R; for a full description: help(Puromycin). We will start with the basic command plot() and tackle each parameter. Generate multiple graphs in the same window using: par(mfrow). For a better understanding use help().

7 Change parameters using par() A list of graphical parameters that define the default behavior of all plot functions. Just like other R objects, par elements are similarly modifiable, with slightly different syntax. e.g. par(“bg”=“lightcyan”) This would change the background color of all subsequent plots to light cyan When par elements are modified directly (as above, this changes all subsequent plotting behavior.

8 Par examples modifiable from within plotting functions bg – plot background color lty – line type (e.g. dot, dash, solid) lwd – line width col – color cex – text size inside plot xlab, ylab – axes labels main – title pch – plotting symbol … and many more (learn as you need them)

9 Plotting symbols for pch Great website for choosing colors: http://research.stowers- institute.org/efg/R/Color/Chart/Color Chart.pdf

10 Multiple plots The number of plots on a page, and their placement on the page, can be controlled using par() or layout(). The number of figure regions can be controlled using mfrow and mfcol. e.g. par(mfrow=c(3,2)) # Creates 6 figures arranged in 3 rows and 2 columns Layout() allows the creation of multiple figure regions of unequal sizes. e.g. layout(matrix(c(1,2)), heights=c(2,1))

11 Graph using statistical function output Many statistical functions (regression, cluster analysis) create special objects. These arguments will automatically format graphical output in a specific way. e.g. Produce diagnostic plots from a linear model analysis (see R code) # Reg = lm() # plot(Reg) hclust() agnes() # hierarchical cluster analysis

12 Save the output Specify destination of graphics output or simply right click and copy Could be files Not Scalable JPG # not recommended, introduces blurry artifacts around the lines BMP PNG Scalable: Postscript # preferred in LaTex Pdf # great for posters

13 Save the output setwd("") # this is where the plot will be saved pdf(file="Puromycin.pdf“, width =, height =, res = ) dev.off()

14 Next - 3D graphs


Download ppt "An Introduction to R graphics Cody Chiuzan Division of Biostatistics and Epidemiology Computing for Research I, 2012."

Similar presentations


Ads by Google