资源描述:
《the r book graphics》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、5GraphicsProducinghigh-qualitygraphicsisoneofthemainreasonsfordoingstatisticalcomputing.Theparticularplotfunctionyouneedwilldependonthenumberofvariablesyouwanttoplotandthepatternyouwishtohighlight.Theplottingfunctionsinthischapteraredealtwithunderfourheadings:plotswithtw
2、ovariables;plotsforasinglesample;multivariateplots;specialplotsforparticularpurposes.ChangestothedetailedlookofthegraphsaredealtwithinChapter29.5.1PlotswithtwovariablesWithtwovariables(typicallytheresponsevariableontheyaxisandtheexplanatoryvariableonthexaxis),thekindof
3、plotyoushouldproducedependsuponthenatureofyourexplanatoryvariable.Whentheexplanatoryvariableisacontinuousvariable,suchaslengthorweightoraltitude,thentheappropriateplotisascatterplot.Incaseswheretheexplanatoryvariableiscategorical,suchasgenotypeorcolourorgender,thentheappr
4、opriateplotiseitherabox-and-whiskerplot(whenyouwanttoshowthescatterintherawdata)orabarplot(whenyouwanttoemphasizetheeffectsizes).ThemostfrequentlyusedplottingfunctionsfortwovariablesinRarethefollowing:plot(x,y)scatterplotofyagainstx;plot(factor,y)box-and-whiskerplotofya
5、teachfactorlevel;barplot(y)heightsfromavectorofyvalues(onebarperfactorlevel).TheRBook,SecondEdition.MichaelJ.Crawley.©2013JohnWiley&Sons,Ltd.Published2013byJohnWiley&Sons,Ltd.190THERBOOK5.2Plottingwithtwocontinuousexplanatoryvariables:ScatterplotsTheplotfunctiondrawsaxes
6、andaddsascatterplotofpoints.Twoextrafunctions,pointsandlines,addextrapointsorlinestoanexistingplot.Therearetwowaysofspecifyingplot,pointsandlinesandyoushouldchoosewhicheveryouprefer:Cartesianplot(x,y)formulaplot(y~x)Theadvantageoftheformula-basedplotisthattheplotfunctio
7、nandthemodelfitlookandfeelthesame(responsevariable,tilde,explanatoryvariable).IfyouuseCartesianplots(eastingsfirst,thennorthings,likethegridreferenceonamap)thentheplothas‘xtheny’whilethemodelhas‘ythenx’.Atitsmostbasic,theplotfunctionneedsonlytwoarguments:firstthenameoftheexp
8、lanatoryvariable(xinthiscase),andsecondthenameoftheresponsevariable(yinthiscase):plot(x,y).Theda