资源描述:
《R 统计软件(画图).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ReviewGettingstartandgettinghelpCalculatorandOperators+*/-^<<=>>===!=Objects:vector,factor,matrix,dataframeandlistControlstructuresConditionalstatementsandLoopDataimportandsaveread.table(),save.image(),saveFromDatatoGraphicsPlot()Thefollowingbothplotyagainstx:plo
2、t(y~x)#Useaformulatospecifythegraphplot(x,y)Tryplot((0:20)*pi/10,sin((0:20)*pi/10),xlab="x",ylab="y")x<-(0:20)*pi/10y<-sin((0:20)*pi/10)plot(y~x)DatasetsthatrelatetolecturenoteDownloadtheRdatafile:usingR.RDatafromISpacePlacethisfileintheworkingdirectoryWithintheR
3、session,type:load("usingR.RData")ls()orobjects()DatasetthatrelatestolecturenotePlot()Example1str(elasticband)plot(distance~stretch,data=elasticband)orattach(elasticband)#Rnowknowswheretofinddistance&stretchplot(distance~stretch)Example2plot(ACT~Year,data=austpop,
4、type="l")plot(ACT~Year,data=austpop,type="b")Trytofindpossibletypeby?plotPlot():addinglines,pointsandtextontheplotExample3plot(ACT~Year,data=austpop,type="n")points(austpop$Year,austpop$ACT,pch=22,col="red")lines(austpop$Year,austpop$ACT,type="l",col="blue")text(
5、austpop$Year[5],austpop$ACT[5],"fifth")title(main="austpop",xlab="Year",ylab="ACT")Note:Thepoints()functionaddspointstoaplot.Thelines()functionaddslinestoaplot.Thetext()functionaddstextatspecifiedlocations.Addalinelines(austpop$Year,austpop$NT,type="b",col="red")
6、Plot():ControllingaxisExample4windows()plot(NT~Year,data=austpop,type="n",xaxt='n',xlab='Year',ylab='NT',main="austpop")axis(1,at=seq(1910,2000,by=10),cex.axis=0.6)points(austpop$Year,austpop$NT,pch=22,col="red")lines(austpop$Year,austpop$NT,type="l",col="blue")t
7、itle(main="austpop")windows()openagraphicswindowTheaxis()functiongivesfinecontroloveraxisticksandlabels.xlim=,ylim=specifiesthelowerandupperlimitsoftheaxes,forexamplewithxlim=c(1,10)orxlim=range(x)Plot():Size,colorandchoiceofplottingsymbolTheparametercex(“charact
8、erexpansion”)controlsthesizeThecol(“colour”)controlsthecolouroftheplottingsymbol.Theparameterpchcontrolsthechoiceofplottingsymbol.Theparameterlwdcontrolsthethi