您好,欢迎访问三七文档
13.1xmm-read.table(file.path(XMM-Newton,XMM-Newton.txt),header=TRUE)counts-sort(table(xmm$Category))par(mfrow=c(1,2),mar=c(3,3,2,2))barplot(counts)dotchart(counts)print(barchart(counts),pos=c(0,0,.5,1),more=TRUE)print(dotplot(counts),pos=c(.5,0,1,1))grid.newpage()catSort-data.frame(Category=factor(xmm$Category,levels=names(counts)))pushViewport(viewport(x=0,width=.5,just=left))print(ggplot(catSort)+geom_bar(aes(x=Category)),newpage=FALSE)popViewport()pushViewport(viewport(x=1,width=.5,just=right))catCounts-data.frame(Category=factor(names(counts),levels=names(counts)),Count=counts)print(ggplot(catCounts)+geom_point(aes(y=Category,x=Count)),newpage=FALSE)popViewport()13.2library(vcd)spine(Priority~Duration,xmm)durn-xmm$Duration/1000cd_plot(Priority~durn,xmm,xlab=Duration(1000s))13.3trellis.par.set(theme=canonical.theme(postscript,color=FALSE))catTab-table(xmm$Schedule,xmm$Priority)print(barchart(prop.table(catTab,margin=1),col=gray(1:3/4)),pos=c(0,0,.5,1),more=TRUE)print(barchart(prop.table(catTab,margin=1),col=gray(1:3/4),stack=FALSE),pos=c(.5,0,1,1))grid.newpage()pushViewport(viewport(x=0,width=.5,just=left))print(ggplot(as.data.frame(prop.table(catTab,margin=1)))+geom_bar(aes(x=Var1,fill=Var2,y=Freq),stat=identity,col=black)+scale_fill_manual(values=gray(1:3/3)),newpage=FALSE)popViewport()pushViewport(viewport(x=1,width=.5,just=right))print(ggplot(as.data.frame(prop.table(catTab,margin=1)))+geom_bar(aes(x=Var1,fill=Var2,y=Freq),stat=identity,col=black,position=dodge)+scale_fill_manual(values=gray(1:3/3)),newpage=FALSE)popViewport()13.4library(vcd)mosaic(Priority~Schedule,xmm)mosaic(nObs~Schedule+Priority,xmm,labeling_args=list(rot_labels=c(right=0),offset_labels=c(right=-.5),just_labels=c(right=left)),margin=c(right=4))13.5library(vcd)grid.rect(gp=gpar(col=NA,fill=gray))tile(nObs~Schedule+Priority,xmm,tile_type=area,shade=TRUE,gp=gpar(lwd=2,fill=white),pos_labels=c(left=left,top=left,right=left),just_labels=c(left=left,top=left,right=left),pop=FALSE,newpage=FALSE)downViewport(cell:Schedule=fixed,Priority=C,nObs=multiple)grid.circle(0,0,r=unit(1,mm))upViewport(0)downViewport(cell:Schedule=fixed,Priority=C,nObs=single)grid.circle(0,0,r=unit(1,mm))upViewport(0)downViewport(cell:Schedule=free,Priority=A,nObs=multiple)grid.circle(0,0,r=unit(1,mm))upViewport(0)downViewport(cell:Schedule=free,Priority=B,nObs=multiple)grid.circle(0,0,r=unit(1,mm))upViewport(0)doubledecker(nObs~Schedule+Priority,xmm,dep_varname=FALSE,gp=gpar(fill=c(gray90,gray)),offset_labels=c(right=-.5),margins=c(bottom=3,left=1,top=1,right=5))13.6xmm-read.table(file.path(XMM-Newton,XMM-Newton.txt),header=TRUE)library(vcd)pairs(structable(nObs~Priority+Schedule,xmm),space=.15)13.7cotabplot(~Schedule+Priority|nObs,xmm)13.8library(vcdExtra)#Needthe.1costhehandlingofzerocellsseemsoff#Alsoneedthecustomshadingtoproducegray-scalemosaic3d(structable(~Priority+Schedule+nObs,xmm)+.1,shading=function(x){gray})
本文标题:R绘图系统13
链接地址:https://www.777doc.com/doc-2856334 .html