R绘图系统7.docx

上传人:b****3 文档编号:24684391 上传时间:2023-05-31 格式:DOCX 页数:11 大小:56.81KB
下载 相关 举报
R绘图系统7.docx_第1页
第1页 / 共11页
R绘图系统7.docx_第2页
第2页 / 共11页
R绘图系统7.docx_第3页
第3页 / 共11页
R绘图系统7.docx_第4页
第4页 / 共11页
R绘图系统7.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

R绘图系统7.docx

《R绘图系统7.docx》由会员分享,可在线阅读,更多相关《R绘图系统7.docx(11页珍藏版)》请在冰豆网上搜索。

R绘图系统7.docx

R绘图系统7

7.1

grid.rect(gp=gpar(col="gray"))

grid.circle(name="circles",x=seq(0.1,0.9,length=40),

y=0.5+0.4*sin(seq(0,2*pi,length=40)),

r=abs(0.1*cos(seq(0,2*pi,length=40))))

grid.edit("circles",

gp=gpar(col=gray(c(1:

20*0.04,20:

1*0.04))))

grid.remove("circles")

 

7.2

grid.rect(gp=gpar(col="gray"))

suffix<-c("even","odd")

for(iin1:

8)

grid.circle(name=paste("circle.",suffix[i%%2+1],

sep=""),

r=(9-i)/20,

gp=gpar(col=NA,fill=gray(i/10)))

grid.edit("circle.odd",gp=gpar(fill="gray10"),

global=TRUE)

grid.edit("circle",gp=gpar(col="gray",fill="gray90"),

grep=TRUE,global=TRUE)

7.3

labels<-c("\"xaxis1\"\nxaxisgTree","\"major\"\nlinesgrob",

"\"ticks\"\nlinesgrob","\"labels\"\ntextgrob")

names<-c("","major","ticks","labels")

boxheight<-unit(2.5,"line")

boxwidth<-unit(1.2,"in")

pushViewport(viewport(layout=grid.layout(2,3)))

pushViewport(viewport(layout.pos.row=1,layout.pos.col=2))

grid.text(labels[1])

grid.lines(unit(0.5,"npc")+unit.c(-0.5*boxwidth,0.5*boxwidth),

0.5,gp=gpar(col="gray"))

grid.roundrect(height=boxheight,

width=boxwidth,#1.2*stringWidth(labels[1]),

r=unit(2,"mm"),

gp=gpar(fill=NA))

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=1))

grid.text(labels[2])

grid.lines(unit(0.5,"npc")+unit.c(-0.5*boxwidth,0.5*boxwidth),

0.5,gp=gpar(col="gray"))

grid.roundrect(height=boxheight,

width=boxwidth,#1.2*stringWidth(labels[2]),

r=unit(2,"mm"),

gp=gpar(fill=NA))

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=2))

grid.text(labels[3])

grid.lines(unit(0.5,"npc")+unit.c(-0.5*boxwidth,0.5*boxwidth),

0.5,gp=gpar(col="gray"))

grid.roundrect(height=boxheight,

width=boxwidth,#1.2*stringWidth(labels[3]),

r=unit(2,"mm"),

gp=gpar(fill=NA))

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=3))

grid.text(labels[4])

grid.lines(unit(0.5,"npc")+unit.c(-0.5*boxwidth,0.5*boxwidth),

0.5,gp=gpar(col="gray"))

grid.roundrect(height=boxheight,

width=boxwidth,#1.2*stringWidth(labels[4]),

r=unit(2,"mm"),

gp=gpar(fill=NA))

popViewport()

pushViewport(viewport(layout.pos.row=1,layout.pos.col=2))

grid.move.to(x=0.5,y=unit(0.5,"npc")-0.5*boxheight)

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=1))

grid.line.to(x=0.5,y=unit(0.5,"npc")+0.5*boxheight,

arrow=arrow(angle=10,length=unit(3,"mm")))

popViewport()

pushViewport(viewport(layout.pos.row=1,layout.pos.col=2))

grid.move.to(x=0.5,y=unit(0.5,"npc")-0.5*boxheight)

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=2))

grid.line.to(x=0.5,y=unit(0.5,"npc")+0.5*boxheight,

arrow=arrow(angle=10,length=unit(3,"mm")))

popViewport()

pushViewport(viewport(layout.pos.row=1,layout.pos.col=2))

grid.move.to(x=0.5,y=unit(0.5,"npc")-0.5*boxheight)

popViewport()

pushViewport(viewport(layout.pos.row=2,layout.pos.col=3))

grid.line.to(x=0.5,y=unit(0.5,"npc")+0.5*boxheight,

arrow=arrow(angle=10,length=unit(3,"mm")))

popViewport()

7.4

grid.rect(gp=gpar(col="gray"))

pushViewport(viewport(just="bottom",gp=gpar(cex=0.7)))

grid.xaxis(name="axis1",at=1:

4/5)

grid.ls()

grid.edit("axis1",at=1:

3/4)

grid.edit(gPath("axis1","labels"),rot=45)

popViewport()

7.5

tg<-textGrob("sampletext")

rg<-rectGrob(width=1.1*grobWidth(tg),

height=1.3*grobHeight(tg))

boxedText<-gTree(children=gList(tg,rg))

pushViewport(viewport(layout=grid.layout(1,7,

heights=unit(1.25,"in"),

widths=unit(rep(c(1,1.25),length=7),

rep(c("null","in"),

length=7)))))

pushViewport(viewport(layout.pos.col=2,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

grid.draw(boxedText)

popViewport()

pushViewport(viewport(layout.pos.col=4,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

grid.draw(editGrob(boxedText,gp=gpar(col="gray")))

popViewport()

pushViewport(viewport(layout.pos.col=6,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

grid.draw(editGrob(boxedText,vp=viewport(angle=45),

gp=gpar(fontsize=18)))

popViewport()

popViewport()

7.6

label<-textGrob("A\nPlot\nLabel",

x=0,just="left")

x<-seq(0.1,0.9,length=50)

y<-runif(50,0.1,0.9)

gplot<-

gTree(

children=gList(rectGrob(gp=gpar(col="gray60",

fill="white")),

linesGrob(x,y),

pointsGrob(x,y,pch=16,

size=unit(1.5,"mm"))),

vp=viewport(width=unit(1,"npc")-unit(5,"mm"),

height=unit(1,"npc")-unit(5,"mm")))

layout<-grid.layout(1,2,

widths=unit(c(1,1),

c("null","grobwidth"),

list(NULL,label)))

grid.rect(gp=gpar(col="gray60",fill="gray90"))

pushViewport(viewport(layout=layout))

pushViewport(viewport(layout.pos.col=2))

grid.draw(label)

popViewport()

pushViewport(viewport(layout.pos.col=1))

grid.draw(gplot)

popViewport

(2)

7.7

tg1<-textGrob("Sample")

rg1<-rectGrob(x=rep(0.5,2),

width=1.1*grobWidth(tg1),

height=1.3*grobHeight(tg1),

gp=gpar(col=c("gray60","white"),

lwd=c(3,1)))

pushViewport(viewport(layout=grid.layout(1,7,

heights=unit(1.25,"in"),

widths=unit(rep(c(1,1.25),length=7),

rep(c("null","in"),

length=7)))))

pushViewport(viewport(layout.pos.col=2,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

grid.draw(tg1)

grid.draw(rg1)

popViewport()

pushViewport(viewport(layout.pos.col=4,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

pushViewport(viewport(gp=gpar(cex=2)))

grid.draw(tg1)

grid.draw(rg1)

popViewport()

popViewport()

pushViewport(viewport(layout.pos.col=6,gp=gpar(fill=NA)))

grid.rect(gp=gpar(col="gray",fill=NA))

pushViewport(viewport(gp=gpar(cex=2)))

grid.draw(tg1)

popViewport()

grid.draw(rg1)

popViewport()

popViewport()

7.8

tg1<-textGrob("Sample",name="tg1")

rg1<-rectGrob(width=1.1*grobWidth("tg1"),

height=1.3*grobHeight("tg1"),

gp=gpar(col="gray60",lwd=3))

rg2<-rectGrob(width=1.1*grobWidth(tg1),

height=1.3*grobHeight(tg1),

gp=gpar(col="white"))

grid.rect(gp=gpar(col="gray"))

pushViewport(viewport(gp=gpar(cex=1.5,fill=NA)))

grid.draw(tg1)

grid.draw(rg1)

grid.draw(rg2)

grid.edit("tg1",grep=TRUE,global=TRUE,

label="Differenttext")

popViewport()

7.9

grid.rect(gp=gpar(col="gray"))

pushViewport(viewport(gp=gpar(fill=NA)))

grid.circle(.25,.5,r=unit(1,"mm"),

gp=gpar(fill="black"))

grid.text("Alabel",.75,.5)

grid.rect(.75,.5,

width=stringWidth("Alabel")+unit(2,"mm"),

height=unit(1,"line"),

name="labelbox")

grid.segments(.25,.5,

grobX("labelbox",180),.5,

arrow=arrow(angle=15,type="closed"),

gp=gpar(fill="black"))

7.10

pushViewport(viewport(gp=gpar(fill=NA)))

vptop<-viewport(width=.9,height=.4,y=.75,

name="vptop")

vpbot<-viewport(width=.9,height=.4,y=.25,

name="vpbot")

pushViewport(vptop)

upViewport()

pushViewport(vpbot)

upViewport()

grid.rect(vp="vptop")

grid.lines(1:

50/51,runif(50),vp="vptop")

grid.rect(vp="vpbot")

grid.lines(1:

50/51,runif(50),vp="vpbot")

grid.null(x=.2,y=.95,vp="vptop",name="tl")

grid.null(x=.4,y=.95,vp="vptop",name="tr")

grid.null(x=.2,y=.05,vp="vpbot",name="bl")

grid.null(x=.4,y=.05,vp="vpbot",name="br")

grid.polygon(unit.c(grobX("tl",0),

grobX("tr",0),

grobX("br",0),

grobX("bl",0)),

unit.c(grobY("tl",0),

grobY("tr",0),

grobY("br",0),

grobY("bl",0)),

gp=gpar(col="gray",lwd=3))

7.11

grid.rect(gp=gpar(col="gray"))

grid.circle(r=0.3,gp=gpar(fill="gray80"),

name="mycircle")

grid.edit("mycircle",gp=gpar(lwd=5))

grid.edit("mycircle",gp=gpar(lty="dashed"))

7.12

angle<-seq(0,2*pi,length=21)[-21]

x<-cos(angle)

y<-sin(angle)

trellis.par.set(theme=canonical.theme("postscript",color=FALSE))

print(

xyplot(y~x,aspect=1,

xlab="displacement",

ylab="velocity")

grid.edit("[.]xlab$",grep=TRUE,

x=unit(1,"npc"),just="right",

gp=gpar(fontfamily="mono"))

grid.edit("[.]ylab$",grep=TRUE,

y=unit(1,"npc"),just="right",

gp=gpar(fontfamily="mono"))

7.13

mtcars2<-mtcars

mtcars2$trans<-factor(mtcars$am,

levels=0:

1,

labels=c("automatic","manual"))

mtcars2$am<-NULL

mtcars2$vs<-NULL

mtcars2$drat<-NULL

mtcars2$carb<-NULL

update_geom_defaults("smooth",aes(color="black"))

print(

ggplot(mtcars2,aes(x=disp,y=mpg))+

geom_point()+

geom_smooth(method=lm)

downViewport("panel.3-4-3-4")

sline<-grid.get(gPath("smooth","polyline"),

grep=TRUE)

grid.segments(.7,.8,

grobX(sline,45),grobY(sline,45),

arrow=arrow(angle=10,type="closed"),

gp=gpar(fill="black"))

grid.text("lineofbestfit",.71,.81,

just=c("left","bottom"))

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 学科竞赛

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1