Lattice and Other Graphics in R J H Maindonald Centre for Mathematics and Its applications Australian National University. J.H.Maindonald 2009.Permission is given to make copies for personal study and class use. Apr14,2009 Languages shape the way we think,and determine what we can think about. Benjamin Whorf. S has forever altered the way people analyze,visualize,and manipulate data...S is an elegant,widely accepted,and enduring software system,with conceptual integrity,thanks to the insight,taste,and effort of John Chambers. [From the citation for the 1998 Association for Computing Machinery Software award.]
Lattice and Other Graphics in R J H Maindonald Centre for Mathematics and Its Applications Australian National University. c J. H. Maindonald 2009. Permission is given to make copies for personal study and class use. April 4, 2009 Languages shape the way we think, and determine what we can think about. [Benjamin Whorf.] S has forever altered the way people analyze, visualize, and manipulate data... S is an elegant, widely accepted, and enduring software system, with conceptual integrity, thanks to the insight, taste, and effort of John Chambers. [From the citation for the 1998 Association for Computing Machinery Software award.]
2 John H.Maindonald,Centre for Mathematics Its Applications,Mathematical Sciences Institute, Australian National University,Canberra ACT 0200,Australia,john.maindonald@anu.edu.au http://www.maths.anu.edu.au/-johnm There will be occasional references to DAAGUR:Maindonald,J.H.Braun,J.B.2007.Data Analysis Graphics Using R.An Example- Based Approach.Cambridge University Press,Cambridge,UK,2007. http://www.maths.anu.edu.au/-johnm/r-book.html Useful Web Sites for Australasian R Users: CRAN (Comprehensive R Archive Network):http://cran.r-project.org To obtain R and associated packages,use the nearest mirror. http://mirror.aarnet.edu.au/pub/CRAN or http://cran.ms.unimelb.edu.au/. Windows,Linux,Unix and MacOS X versions are available,at no cost. R homepage:http://www.r-project.org/ Wikipedia:http://en.wikipedia.org/wiki/R_(programming_language) R-downunder:http://www.stat.auckland.ac.nz/mailman/listinfo/r-downunder For other useful web pages,click on the menu item R help,and look under Resources on the browser window that pops up. Source of Information on R Graphics: Helpful books on R graphics,with web sites that give code,are: Paul Murrell:R Graphics.Chapman and Hall/CRC 2006. (http://www.stat.auckland.ac.nz/-paul/RGraphics/rgraphics.html) Deepayan Sarkar:Lattice.Multivariate Data Visualization with R.Springer 2008. (http://lmdvr.r-forge.r-project.org). The CRAN Graphics task view(http://cran.ms.unimelb.edu.au/web/views/Graphics.html) has summary information on a rich variety of R graphics packages. Note also Hadley Wickham's forthcoming book on ggplot2.A draft is available from http://had. co.nz/ggplot2
2 John H. Maindonald, Centre for Mathematics & Its Applications, Mathematical Sciences Institute, Australian National University, Canberra ACT 0200, Australia, john.maindonald@anu.edu.au http://www.maths.anu.edu.au/~johnm There will be occasional references to DAAGUR: Maindonald, J. H. & Braun, J. B. 2007. Data Analysis & Graphics Using R. An ExampleBased Approach. Cambridge University Press, Cambridge, UK, 2007. http://www.maths.anu.edu.au/~johnm/r-book.html Useful Web Sites for Australasian R Users: CRAN (Comprehensive R Archive Network): http://cran.r-project.org To obtain R and associated packages, use the nearest mirror. http://mirror.aarnet.edu.au/pub/CRAN or http://cran.ms.unimelb.edu.au/. Windows, Linux, Unix and MacOS X versions are available, at no cost. R homepage: http://www.r-project.org/ Wikipedia: http://en.wikipedia.org/wiki/R_(programming_language) R-downunder: http://www.stat.auckland.ac.nz/mailman/listinfo/r-downunder For other useful web pages, click on the menu item R help, and look under Resources on the browser window that pops up. Source of Information on R Graphics: Helpful books on R graphics, with web sites that give code, are: Paul Murrell: R Graphics. Chapman and Hall/CRC 2006. (http://www.stat.auckland.ac.nz/~paul/RGraphics/rgraphics.html) Deepayan Sarkar: Lattice. Multivariate Data Visualization with R. Springer 2008. (http://lmdvr.r-forge.r-project.org). The CRAN Graphics task view (http://cran.ms.unimelb.edu.au/web/views/Graphics.html) has summary information on a rich variety of R graphics packages. Note also Hadley Wickham’s forthcoming book on ggplot2. A draft is available from http://had. co.nz/ggplot2
Contents 1 Preliminaries 5 1.1 Installation of R and of R Packages.··.·。··.··················· 5 l.l.1 nstallation of packages from the command line..,··.···········, 5 l.2 The R Commander,································ 6 1.3 The R Commander GUI 6 2 Base Graphics 9 2 1 plot()and allied functions.:·。·.························· 9 2.l.1 Fine control-parameter settings...............·.·.·.····· 9 2.l.2 Adding points,lines and text-examples····················· 2.2 Plotting Mathematical Symbols..........·..··......·....·.... 12 2.3 Summary 12 2.4 Exercises 3 Lattice Graphics 15 3.1 Lattice Graphics 15 3.1.1 Groups within data,and/or columns in parallel ................. 18 3.l.2 Lattice Parameters and Graphics Features.,.·················· 19 3.1.3 Setting that are not available using simpleTheme() 20 3.l.4Keys-auto.key,key&legend.......................... 21 3.1.5 Panel functions and interaction with plots.. 2 3.l.6 Interaction with lattice plots-focus,interact,.unfocus.......·:···.. 22 3.1.7 Arbitrary placement of labels.···.·············· 2 3.l.8 Multiple graphs on a single graphics page····················· 23 3.l.9 Plots that Show Distributions.·.·.....·..·.·...。.. 24 4 The ggplot2 Package 27 4.2 Dynamic Graphics-the rgl package............................ 29 5 References and Bibliography 31 5.1 Books and Papers on R..······ 5.2Web-Based Information······· 1 5.3 Graphics.·。··········· 32 3
Contents 1 Preliminaries 5 1.1 Installation of R and of R Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1.1 Installation of packages from the command line . . . . . . . . . . . . . . . . . . 5 1.2 The R Commander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.3 The R Commander GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Base Graphics 9 2.1 plot() and allied functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.1 Fine control – parameter settings . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1.2 Adding points, lines and text – examples . . . . . . . . . . . . . . . . . . . . . 11 2.2 Plotting Mathematical Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 3 Lattice Graphics 15 3.1 Lattice Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.1.1 Groups within data, and/or columns in parallel . . . . . . . . . . . . . . . . . . 18 3.1.2 Lattice Parameters and Graphics Features . . . . . . . . . . . . . . . . . . . . . 19 3.1.3 Setting that are not available using simpleTheme() . . . . . . . . . . . . . . . 20 3.1.4 Keys – auto.key, key & legend . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1.5 Panel functions and interaction with plots . . . . . . . . . . . . . . . . . . . . . 21 3.1.6 Interaction with lattice plots – focus, interact, unfocus . . . . . . . . . . . . . . 22 3.1.7 Arbitrary placement of labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.1.8 Multiple graphs on a single graphics page . . . . . . . . . . . . . . . . . . . . . 23 3.1.9 Plots that Show Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4 The ggplot2 Package 27 4.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.2 Dynamic Graphics – the rgl package . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5 References and Bibliography 31 5.1 Books and Papers on R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.2 Web-Based Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 5.3 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3
4 CONTENTS
4 CONTENTS
Chapter 1 Preliminaries The "preliminaries"that are discussed here will extend to using the R Commander menu to draw graphs! 1.1 Installation of R and of R Packages Installation of R First download and install R from a CRAN site,e.g. http://cran.ms.unimelb.edu.au/or http://mirror.aarnet.edu.au/pub//CRAN/ Windows an MacOS X users should download the relevant executable. (e.g.R-2.7.0-win32.exe for Windows,or R-2.7.0.dmg for MacOS X), and open the downloaded file (e.g.,click on it)to start insallation Installation of R Packages (Windows MacOS X) Start R(e.g.,click on the R icon).Then use the relevant menu item to install packages via an internet connection. This is(usually)easier than downloading,then installing. Locating packages The CRAN task views may be a good first place to go. For installation,follow the instructions in the text box.For installing packages,Windows users will first need to specify a mirror.In Australia,specify the Australian mirror. A fresh install is typically required to take advantage of new major releases (e.g.moving from a 2.6 series release to a 2.7 series release)when they appear.For working through these notes,version 2.7.0 or later should be installed. 1.1.1 Installation of packages from the command line For packages where there are dependencies,installation from the command line may be an attractive way to go.First,start R,perhaps by clicking on an R icon.Make sure that you have a live internet connection. For the R Commander,enter: install.packages("Rcmdr",dependencies=TRUE) Doing the installation this way ensures that other packages that R Commander may want get installed at the same time.One of those packages is the rgl 3D graphics package that I will describe briefly. Other graphics packages that this installs are scatterplot3d,ucd(visualization of categorical data)and colorspace (for generation of color palettes,etc)
Chapter 1 Preliminaries The “preliminaries” that are discussed here will extend to using the R Commander menu to draw graphs! 1.1 Installation of R and of R Packages Installation of R First download and install R from a CRAN site, e.g. http://cran.ms.unimelb.edu.au/ or http://mirror.aarnet.edu.au/pub//CRAN/ Windows an MacOS X users should download the relevant executable, (e.g. R-2.7.0-win32.exe for Windows, or R-2.7.0.dmg for MacOS X), and open the downloaded file (e.g., click on it) to start insallation Installation of R Packages (Windows & MacOS X) Start R (e.g., click on the R icon). Then use the relevant menu item to install packages via an internet connection. This is (usually) easier than downloading, then installing. Locating packages The CRAN task views may be a good first place to go. For installation, follow the instructions in the text box. For installing packages, Windows users will first need to specify a mirror. In Australia, specify the Australian mirror. A fresh install is typically required to take advantage of new major releases (e.g. moving from a 2.6 series release to a 2.7 series release) when they appear. For working through these notes, version 2.7.0 or later should be installed. 1.1.1 Installation of packages from the command line For packages where there are dependencies, installation from the command line may be an attractive way to go. First, start R, perhaps by clicking on an R icon. Make sure that you have a live internet connection. For the R Commander, enter: install . packages ( " Rcmdr " , dependencies = TRUE ) Doing the installation this way ensures that other packages that R Commander may want get installed at the same time. One of those packages is the rgl 3D graphics package that I will describe briefly. Other graphics packages that this installs are scatterplot3d, vcd (visualization of categorical data) and colorspace (for generation of color palettes, etc). 5
6 CHAPTER 1.PRELIMINARIES A further package that will be discussed here,the ggplot?package,is not an R commander suggested package,and requires separate installation.Enter,at the command line: install("ggplot2",dependencies=TRUE) 1.2 The R Commander 1.3 The R Commander GUI The R commander gives a graphical user interface(GUI)to a wide range of abilities,in the base R system and in R packages.This includes graphical abilities,in the lattice and rgl packages as well as in base graphics. To start the R commander,start up R and enter:1 library(Rcmdr) This opens an R Commander script window,with the output window underneath.This window can be closed by clicking on the x in the top left corner.If thus closed,enter Commander()to reopen it again later in the session. The R Commander GUI-a guide to getting started Once the points that will now be noted are understood,use of the R Commander should for the most part be straightforward. From GUI to writing code:The R commander displays the code that it generates.Users can take this code,modify it,and re-run it.The code can be run either from the R Commander script window or from the R console window (if open). The active data set:The R commander has the notion of an active data set.Here are alternative ways to make a data set active.Start by clicking on the Data drop-down menu.Then Click on Active data set,and pick from among data sets,if any,in the workspace. Click on Import data,and follow instructions,to read in data from a file.The data set is read into the workspace,at the same time becoming the active data set. Click on New data set...,then entering data via a spreadsheet-like interface. Click on Data in packages,click on Read Data from Package,then identify one of the attached packages and choose a data set from among those that are included with the package. A further possibility is to load data from an R image(.RData)file;click on Load data set... Creating graphs:To draw graphs,click on the Graphs drop-down menu.Then Click on Scatterplot...to obtain a scatterplot.This uses the function scatterplot()from the car package,which is an option rich interface to functions that are in base graphics. .Click on X Y conditioning plot...for lattice scatterplots and panels of scatterplots. Click on 3D graph to obtain a 3D scatterplot,using the R Commander function scatter3d() that is an interface to functions in the rgl package. 1At startup,the R Commander checks whether all the suggested packages,needed to use all its features,are available. If some are missing,then upon starting up,the R commander offers to install them.For installing such packages,there must be a live internet connection
6 CHAPTER 1. PRELIMINARIES A further package that will be discussed here, the ggplot2 package, is not an R commander suggested package, and requires separate installation. Enter, at the command line: install ( " ggplot2 " , dependencies = TRUE ) 1.2 The R Commander 1.3 The R Commander GUI The R commander gives a graphical user interface (GUI) to a wide range of abilities, in the base R system and in R packages. This includes graphical abilities, in the lattice and rgl packages as well as in base graphics. To start the R commander, start up R and enter:1 library ( Rcmdr ) This opens an R Commander script window, with the output window underneath. This window can be closed by clicking on the × in the top left corner. If thus closed, enter Commander() to reopen it again later in the session. The R Commander GUI – a guide to getting started Once the points that will now be noted are understood, use of the R Commander should for the most part be straightforward. From GUI to writing code: The R commander displays the code that it generates. Users can take this code, modify it, and re-run it. The code can be run either from the R Commander script window or from the R console window (if open). The active data set: The R commander has the notion of an active data set. Here are alternative ways to make a data set active. Start by clicking on the Data drop-down menu. Then • Click on Active data set, and pick from among data sets, if any, in the workspace. • Click on Import data, and follow instructions, to read in data from a file. The data set is read into the workspace, at the same time becoming the active data set. • Click on New data set . . . , then entering data via a spreadsheet-like interface. • Click on Data in packages, click on Read Data from Package, then identify one of the attached packages and choose a data set from among those that are included with the package. • A further possibility is to load data from an R image (.RData) file; click on Load data set . . . Creating graphs: To draw graphs, click on the Graphs drop-down menu. Then • Click on Scatterplot . . . to obtain a scatterplot. This uses the function scatterplot() from the car package, which is an option rich interface to functions that are in base graphics. • Click on X Y conditioning plot . . . for lattice scatterplots and panels of scatterplots. • Click on 3D graph to obtain a 3D scatterplot, using the R Commander function scatter3d() that is an interface to functions in the rgl package. 1At startup, the R Commander checks whether all the suggested packages, needed to use all its features, are available. If some are missing, then upon starting up, the R commander offers to install them. For installing such packages, there must be a live internet connection
1.3.THE R COMMANDER GUI 7 Statistics(&fitting models):Click on the Statistics drop down menu to get submenus that give summary statistics and/or carry out various statistical tests.This includes(under Contingency tables) tables of counts and(under Means)One-way ANOVA.Also,click here to get access to the Fit models submenu. *Models:Click here to extract information from model objects once they have been fitted.(NB: To fit a model,go to the Statistics drop down menu,and click on Fit models)
1.3. THE R COMMANDER GUI 7 Statistics (& fitting models): Click on the Statistics drop down menu to get submenus that give summary statistics and/or carry out various statistical tests. This includes (under Contingency tables) tables of counts and (under Means) One-way ANOVA. Also, click here to get access to the Fit models submenu. *Models: Click here to extract information from model objects once they have been fitted. (NB: To fit a model, go to the Statistics drop down menu, and click on Fit models)
8 CHAPTER 1.PRELIMINARIES
8 CHAPTER 1. PRELIMINARIES
Chapter 2 Base Graphics Base Graphics implements a relatively "traditional"style of graphics: Plots go to one or more pages of a graphics device(screen,or hardcopy) plot(),etc. Sets up figure region,with user region inside,usually starts the graph. Other functions that initiate a graph include hist()and boxplot(). Typically,it also creates the main part,or all,of the graph. Use points(),lines(),text(),mtext(),axis(),rug(),identify(),etc., to add to the graph. Plot y vs x with(women,plot(height,weight))#0lder syntax plot(weight height,data=women)#Newer syntax (graphics formula) Caveat Some base graphics functions do not take a data parameter To see some of the possibilities that traditional(or base)R graphics offers,enter demo (graphics) Press the Enter key to move to each new graph. 2.1 plot()and allied functions Here are two examples. library(DAAG) attach(elasticband)R can now find distance stretch plot(distance ~stretch) plot(ACT year,data=austpop,type="1") plot(ACT-year,data-austpop,type="b") detach(elasticband) Figure 2.1 demonstrates some of the features of base graphics.Base graphics is highly flexible, but often requires a great deal of attention to detail.There are annoying inconsistencies. 2.1.1 Fine control-parameter settings Users who execute the code given above for Figure 2.1 will notice that the layout is different;there will be bigger margins,and the tick labels and the axis labels will be further out.To get the layout shown,there were some small changes to parameter settings: #Invoke once device is open,and before starting the plot oldpar <-par(mar =rep(2,4),xaxs="i",yaxs="i",mgp=c(1.5,0.75,0))
Chapter 2 Base Graphics Base Graphics implements a relatively “traditional” style of graphics: Plots go to one or more pages of a graphics device (screen, or hardcopy) plot(), etc. Sets up figure region, with user region inside, usually starts the graph. Other functions that initiate a graph include hist() and boxplot(). Typically, it also creates the main part, or all, of the graph. Use points(), lines(), text(), mtext(), axis(), rug(), identify(), etc., to add to the graph. Plot y vs x with(women, plot(height, weight)) # Older syntax plot(weight ∼ height, data=women) # Newer syntax (graphics formula) Caveat Some base graphics functions do not take a data parameter To see some of the possibilities that traditional (or base) R graphics offers, enter demo ( graphics ) Press the Enter key to move to each new graph. 2.1 plot() and allied functions Here are two examples. library ( DAAG ) attach ( elasticband ) # R can now find distance & stretch plot ( distance ~ stretch ) plot ( ACT ~ year , data = austpop , type = " l " ) plot ( ACT ~ year , data = austpop , type = " b " ) detach ( elasticband ) Figure 2.1 demonstrates some of the features of base graphics. Base graphics is highly flexible, but often requires a great deal of attention to detail. There are annoying inconsistencies. 2.1.1 Fine control – parameter settings Users who execute the code given above for Figure 2.1 will notice that the layout is different; there will be bigger margins, and the tick labels and the axis labels will be further out. To get the layout shown, there were some small changes to parameter settings: # # Invoke once device is open , and before starting the plot oldpar <- par ( mar = rep (2 ,4) , xaxs = " i " , yaxs = " i " , mgp = c (1.5 ,0.75 ,0)) 9
10 CHAPTER 2.BASE GRAPHICS Side 3 ##A:Set up plotting region,but(type="n")do not plot.Suppress axes axis labels plot(0~0,xlim=c(0,26.5),ylim=c(-0.05,34.25),xlab=M,ylab="",type="n",axes=FALSE) 男 ##B:Plot symbols 0-25.Overlay with numbers 0-25 grayscale <-gray(seq(from=0.1,by=0.05,length=13)) xpos <-seq(from=1,by=2,length=13);ypos <-rep(23,13);ypos2 <-ypos-2 points(ypos~xpos,cex=3,col=grayscale,pch=0:12) points(ypos2~xpos,cex=3,col=rev(grayscale),pch=13:25) text(ypos~xpos,labels=paste(0:12),cex=0.75) text(ypos2 ~xpos,labels=paste(13:25).cex=0.75) o ① 公+X⑥可☒米令 、2 -23 03 4 156位6002④ 2 ③A 啊 21 ##C:Enlarged and/or coloured symbols or text 18 Xp0s<-c(21.5,23.5,25.5):yp0s<-rep(18,3):yp0s2<-ypos-2 points(ypos~xpos,pch=0:2,cex=4:2,col=gray(c(.2,.4,.6))) text(ypos2 ~xpos,labels=letters[1:3],cex=2:4,col=gray(c(.2,.4,.6))) a 16 ##D:Positioning of label with respect to a point p0s<-c(22.5,21.5,22.5,23.5) above(3) yp0s<-c(10,11,12,11) ● 12 let(2)● ●ight(4) 11 points(ypos~xpos,pch=16,cex=1.5,col=gray((1:4)/5)) posText <-c("below (pos=1)","left(2)"."above (3)","right (4)") 10 below(pos=1) text(ypos~xpos,posText,pos=1:4) ##E:Sides (margins)are numbered 1,...4.Label them acordingly mtext(side=4,line=0.5,text="Side 4",adj=1)#Flush right on margin (Flush left:adj=0) ##Center labels in margins 1 to 3 for(i in 1:3)mtext(side=i,line=0.5,text=paste("Side",i)) #Label selected plotting positions 1abp0s<-c0,10:12,16,18,21,23) for(pos in labpos)axis(side=4,at=pos,las=2) 0 Side 1 Figure 2.1:Here are illustrated a number of features of traditional graphics plots.The code reproduces the points,labels,ticks,tick labels and axis labels,but not the printing of the code in the figure region
10 CHAPTER 2. BASE GRAPHICS ##A: Set up plotting region, but (type="n") do not plot. Suppress axes & axis labels plot(0 ~ 0, xlim=c(0, 26.5), ylim=c(−0.05, 34.25), xlab="", ylab="", type="n", axes=FALSE) ##B: Plot symbols 0 − 25. Overlay with numbers 0 − 25 ● ● grayscale <− gray(seq(from=0.1, by=0.05, length=13)) xpos <− seq(from=1, by=2, length=13); ypos <− rep(23,13); ypos2 <− ypos−2 points(ypos ~ xpos, cex=3, col=grayscale, pch=0:12) ● ● ● ● ● points(ypos2 ~ xpos, cex=3, col=rev(grayscale), pch=13:25) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 text(ypos ~ xpos, labels=paste(0:12), cex=0.75) text(ypos2 ~ xpos, labels=paste(13:25), cex=0.75) ##C: Enlarged and/or coloured symbols or text xpos <− c(21.5, 23.5, 25.5); ypos <− rep(18, 3); ypos2 <− ypos−2 points(ypos ~ xpos, pch=0:2, cex=4:2, col=gray(c(.2, .4, .6))) ● text(ypos2 ~ xpos, labels=letters[1:3], cex=2:4, col=gray(c(.2, .4, .6))) a b c ##D: Positioning of label with respect to a point xpos <− c(22.5, 21.5, 22.5, 23.5) ypos <− c(10, 11, 12, 11) points(ypos ~ xpos, pch=16, cex=1.5, col=gray((1:4)/5)) ● ● ● ● posText <− c("below (pos=1)", "left (2)", "above (3)", "right (4)") below (pos=1) left (2) above (3) right (4) text(ypos ~ xpos, posText, pos=1:4) ##E: Sides (margins) are numbered 1, ...4. Label them acordingly Side 4 Side 1 Side 2 Side 3 mtext(side=4, line=0.5, text="Side 4", adj=1) # Flush right on margin (Flush left: adj=0) ## Center labels in margins 1 to 3 for (i in 1:3) mtext(side=i, line=0.5, text=paste("Side",i)) ## Label selected plotting positions labpos <− c(0, 10:12, 16, 18, 21, 23) for (pos in labpos) axis(side=4, at=pos, las=2) 0 10 11 12 16 18 21 23 Figure 2.1: Here are illustrated a number of features of traditional graphics plots. The code reproduces the points, labels, ticks, tick labels and axis labels, but not the printing of the code in the figure region