10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appendix D 359In the example at the end of this appendix, the layout () function is used to break thefigure into four regions of varying sizes. This function uses a matrix to set up a grid andan order to fill in the plots. The size of the grid is controlled with the arguments widths=and heights=. In the example, the function call islayout(matrix(c(1,0, # which order to place graphs3,2),2,2,byrow=TRUE),widths=c(3,1), # 3/4 wide <strong>for</strong> col. 1heights=c(1,3), # 3/4 wide <strong>for</strong> row 2respect=TRUE)# make squareThe matrix specifies how the figure is filled. In this case upper left, lower right, lowerleft. The value of widths= says to make the first column three times as wide as thesecond; <strong>for</strong> heights= the top row is one-quarter the height of the bottom one.When there are multiple plot figures per overall figure, there is an outer margin that iscontrolled by omi=. Values are specified in inches. The arguments oma= and omd= allowyou to specify values in lines of text and fractions of a whole respectively.Setting up the coordinate system and axes of a graphicWhen creating a plot figure, the x-and y-limits are specified, allowing locations to bespecified in a Cartesian manner. This is done with plot. window(), using the argumentsxlim= and ylim=. Values contain the minimum and maximum values of the desiredrange. Additionally, the parameter asp= can be set to give the aspect ratio in terms ofwidth/height.Once the coordinates are chosen, axes <strong>for</strong> a figure can be added with the axis ()function. The common arguments areaxis(side=…, at=…, labels=…)The value of side= is specified with 1, 2, 3, or 4, with 1 being the bottom of the figureand other values moving around clockwise. The value of at= allows us to override thedefault placement of the tick marks. The labels= argument can adjust the labels on thetick marks.The axis () function can be used with high-level plotting functions to create customaxes if you explicitly ask <strong>for</strong> the axes not to be drawn when first plotting. This is done byspecifying the arguments xaxt="n" and yaxt="n" to the highlevel plot function.Adding titles and labels to a figureThe title () function adds titles and labels the axes. The main arguments aretitle(main=…, sub=…, xlab=…, ylab=…)The value of main= is written in the top margin of the figure. The value of sub= is writtenin the bottom margin below the x-label, which is specified with xlab=. The y-label isspecified with ylab=.If more control is needed, the mtext () function will add text to the margins of a figure.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!