您好,欢迎访问三七文档
2.1par(mfrow=c(2,2),cex=0.6,mar=c(4,4,1,1))y-rnorm(20)plot(y,type=p)plot(y,type=l)plot(y,type=b)plot(y,type=h)2.2par(mfrow=c(2,2),cex=0.6,mar=c(4,4,4,2),mex=0.8)plot(lm.SR-lm(sr~pop15+pop75+dpi+ddpi,data=LifeCycleSavings),id.n=1,cex.caption=0.8,which=1:4,panel=function(...){panel.smooth(...,col.smooth=gray)})2.3library(cluster)subset-sample(1:150,20)cS-as.character(Sp-iris$Species[subset])cS[Sp==setosa]-ScS[Sp==versicolor]-VcS[Sp==virginica]-gai-agnes(iris[subset,1:4])par(mfrow=c(2,1),cex=0.5,pty=s)plot(ai,which=1,col=c(gray90,gray),labels=cS)plot(ai,which=2,labels=cS)2.4plottitle-function(plotfun,funarg,outer=FALSE,cex=.7,line=1){ncp-nchar(plotfun)nca-nchar(funarg)mtext(paste(plotfun,(,paste(rep(,nca),collapse=),),sep=),family=mono,cex=cex,line=line,font=2,outer=outer)mtext(paste(paste(rep(,ncp+1),collapse=),funarg,,sep=),family=mono,col=gray60,cex=cex,line=line,font=2,outer=outer)}plot2title-function(plotfun,funarg,extrafn,extraarg,outer=FALSE,cex=.7,line=.5){ncp-nchar(plotfun)nca-nchar(funarg)ncep-nchar(extrafn)ncea-nchar(extraarg)mtext(paste(plotfun,(,paste(rep(,nca),collapse=),)\n,extrafn,(,paste(rep(,ncea),collapse=),),sep=),family=mono,cex=cex,line=line,font=2,outer=outer)mtext(paste(paste(rep(,ncp+1),collapse=),funarg,\n,paste(rep(,ncep+1),collapse=),extraarg,,sep=),family=mono,col=gray60,cex=cex,line=line,font=2,outer=outer)}dohplot-function(plotfn,...,funarg,extrafn=NULL,extraarg=NULL,namefudge=FALSE,main=,xlab=,ylab=,axes=FALSE,box=TRUE){if(is.null(xlab)||is.null(ylab)){do.call(plotfn,list(...,main=))}elseif(is.null(axes)){do.call(plotfn,list(...,main=,xlab=,ylab=))}else{do.call(plotfn,list(...,main=,axes=FALSE,xlab=,ylab=))}if(is.null(extrafn)){plottitle(plotfn,funarg)}else{plot2title(if(namefudge)paste(,plotfn,sep=)elseplotfn,funarg,extrafn,extraarg)}if(box)box()#col=gray)}par(mfrow=c(3,4),mar=c(1,1,3,1),mex=.7,mgp=c(3,100,100))dohplot(plot,(1:10)^2,funarg=numeric,xlim=c(0,11),ylim=c(-10,110))dohplot(plot,table(rep(1:3,1:3)),funarg=table,lwd=2,xlim=c(0,4),ylim=c(0,4))#Emptyplot.new()plot.new()dohplot(barplot,table(rep(1:3,1:3)),funarg=,extrafn=plot,extraarg=factor,xlim=c(-1,5),ylim=c(0,4),names.arg=)dohplot(pie,c(1,2,4),funarg=,col=gray(1:3/4),cex=.7,labels=,axes=NULL)dohplot(dotchart,1:3,funarg=numeric,pch=21,bg=gray,lcolor=black,xlim=c(0,4))#Emptyplot.new()dohplot(boxplot,(1:10)^2,funarg=numeric,col=gray,ylim=c(-10,110))dohplot(hist,(1:100)^2,funarg=,col=gray,breaks=6,xlim=c(-1000,11000),ylim=c(0,50))dohplot(stripchart,(1:10)^2,funarg=numeric,method=stack,cex=1,xlim=c(-10,110),ylim=c(-1,3),pch=21,bg=gray)#stem()plot.new()txt-capture.output(stem((1:10)^2))[-2]text(.05,(1:length(txt))/(length(txt)+1),txt,adj=0,family=mono,cex=.7)box()#col=gray)plottitle(stem,)2.5plottitle-function(plotfun,funarg,outer=FALSE,cex=.7,line=1){ncp-nchar(plotfun)nca-nchar(funarg)mtext(paste(plotfun,(,paste(rep(,nca),collapse=),),sep=),family=mono,cex=cex,line=line,font=2,outer=outer)mtext(paste(paste(rep(,ncp+1),collapse=),funarg,,sep=),family=mono,col=gray60,cex=cex,line=line,font=2,outer=outer)}plot2title-function(plotfun,funarg,extrafn,extraarg,outer=FALSE,cex=.7,line=.5){ncp-nchar(plotfun)nca-nchar(funarg)ncep-nchar(extrafn)ncea-nchar(extraarg)mtext(paste(plotfun,(,paste(rep(,nca),collapse=),)\n,extrafn,(,paste(rep(,ncea),collapse=),),sep=),family=mono,cex=cex,line=line,font=2,outer=outer)mtext(paste(paste(rep(,ncp+1),collapse=),funarg,\n,paste(rep(,ncep+1),collapse=),extraarg,,sep=),family=mono,col=gray60,cex=cex,line=line,font=2,outer=outer)}dohplot-function(plotfn,...,funarg,extrafn=NULL,extraarg=NULL,namefudge=FALSE,main=,xlab=,ylab=,axes=FALSE,box=TRUE){if(is.null(xlab)||is.null(ylab)){do.call(plotfn,list(...,main=))}elseif(is.null(axes)){do.call(plotfn,list(...,main=,xlab=,ylab=))}else{do.call(plotfn,list(...,main=,axes=FALSE,xlab=,ylab=))}if(is.null(extrafn)){plottitle(plotfn,funarg)}else{plot2title(if(namefudge)paste(,plotfn,sep=)elseplotfn,funarg,extrafn,extraarg)}if(box)box()#col=gray)}set.seed(1500)#mgpdrawstheaxesmilesoffthepagepar(mfrow=c(4,4),mar=c(1,1,3,1),mex=.7,mgp=c(3,100,100))dohplot(plot,1:10,(1:10)^2,funarg=num,num,pch=21,bg=gray,xlim=c(0,11),ylim=c(-10,110))x-rnorm(10000)dohplot(smoothScatter,x,x+rnorm(10000)/3,funarg=,nbin=64,colramp=function(n){gray(n:1/(n+1))},xlim=c(-5,5),ylim=c(-5,5))x-sample(1:4,20,replace=TRUE)y-x+sample(0:1,20,replace=TRUE)dohplot(sunflowerplot,x,y,funarg=,seg.col=black,size=.07,xlim=c(0,5),ylim=c(0,6))#Emptygapplot.new()dohplot(boxplot,list((1:10)^2,120-(1:10)^2),funarg=list,extrafn=plot,extraarg=fac,num,col=gray,boxwex=0.5,ylim=c(-10,130))dohplot(barplot,rbind(1:3,(1:3)^2),funarg=matrix,xlim=c(0,4),ylim=c(0,13))dohplot(barplot,rbind(1:3,(1:3)^2),funarg=matrix,beside=TRUE,xlim=c(0,10),ylim=c(0,11))#Emptygapfordotchartplot.new()fig-par(fig)dohplot(stripchart,list((1:10)^2,140-(1:10)^2),funarg=list,extrafn=plot,extraarg=num,fac,xlim=c(-10,150),ylim=c(0,3),pch=21,bg=gray,cex=1)dohplot(spineplot,rep(1:3,each=6),factor(c(rep(1:3,3:1),rep(1
本文标题:R绘图系统2
链接地址:https://www.777doc.com/doc-2856340 .html