正在加载图片...
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
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有