资源描述:
《reilly media] r cookbook graphics》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、CHAPTER10GraphicsIntroductionGraphicsisagreatstrengthofR.Thegraphicspackageispartofthestandarddistri-butionandcontainsmanyusefulfunctionsforcreatingavarietyofgraphicdisplays.Thischapterfocusesonthosefunctions,althoughitoccasionallysuggestsotherpack-ages.Inthischapter’sSeeAlsosectionsImentionfunc
2、tionsinotherpackagesthatdothesamejobinadifferentway.Isuggestthatyouexplorethosealternativesifyouaredissatisfiedwiththebasicfunction.Graphicsisavastsubject,andIcanonlyscratchthesurfacehere.Ifyouwanttodelvedeeper,IrecommendRGraphicsbyPaulMurrell(Chapman&Hall,2006).Thatbookdiscussestheparadigmsbehi
3、ndRgraphics,explainshowtousethegraphicsfunctions,andcontainsnumerousexamples—includingthecodetorecreatethem.Someoftheexamplesareprettyamazing.TheIllustrationsThegraphsinthischapteraremostlyplainandunadorned.Ididthatintentionally.Whenyoucalltheplotfunction,asin:>plot(x)yougetaplain,graphicalrepre
4、sentationofx.Youcouldadornthegraphwithcolors,atitle,labels,alegend,text,andsoforth,butthenthecalltoplotbecomesmoreandmorecrowded,obscuringthebasicintention:>plot(x,main="ForecastResults",xlab="Month",ylab="Production",+col=c("red","black","green"))Iwanttokeeptherecipesclean,soIemphasizethebasicp
5、lotandthenshowlater(asinRecipe10.2)howtoaddadornments.221NotesonGraphicsFunctionsItisimportanttounderstandthedistinctionbetweenhigh-levelandlow-levelgraphicsfunctions.Ahigh-levelgraphicsfunctionstartsanewgraph.Itinitializesthegraphicswindow(creatingitifnecessary);setsthescale;maybedrawssomeadorn
6、ments,suchasatitleandlabels;andrendersthegraphic.Examplesinclude:plotGenericplottingfunctionboxplotCreateaboxplothistCreateahistogramqqnormCreateaquantile-quantile(Q-Q)plotcurveGraphafunctionAlow-levelgraphicsfunctioncannotstartanewgraph.Rather,itaddssomethingtoanexistinggraph:points,lines,text,
7、adornments,andsoforth.Examplesinclude:pointsAddpointslinesAddlinesablineAddastraightlinesegmentsAddlinesegmentspolygonAddaclosedpolygontextAddtextYoumustcallahigh-levelgraphicsroutinebeforecallingalow-levelgraphicsroutine.Th