初学R语言,尝试着写了一个函数,调用这个函数,生成一些曲线。
###############################################################################
PictureLine <- function(name.picture,width.picture=1400,height.picture=1400,
width.line=1,x.limit,y.limit,lwd.grid=2,
x.legend,y.legend,cex.legend=3,cex.point=2,
number.grid.major.x,number.grid.minor.x,
number.grid.major.y,number.grid.minor.y,colum.x,colum.y,
x.axis,new.x.axis,y.axis,new.y.axis,picture.legend){
jpeg(name.picture,width=width.picture,height=height.picture*(number.grid.major.y/number.grid.major.x))
oldpar<-par(no.readonly=TRUE)
par(pin=c(width.picture/100,
height.picture/100*(number.grid.major.y/number.grid.major.x)),
lwd=width.line,cex.axis=2.5)
plot( mydate_z20[,colum.x],mydate_z20[,colum.y],type<-"p",pch=0,cex=cex.point,
yaxt="no",xaxt="no",xlim=x.limit,ylim=y.limit,xaxs="i",yaxs="i",
ann=FALSE)
xspline(mydate_z20[,colum.x],mydate_z20[,colum.y],0.2)
lines( mydate_z10[,colum.x],mydate_z10[,colum.y],type<-"p",pch=1,cex=cex.point)
xspline(mydate_z10[,colum.x],mydate_z10[,colum.y],0.2)
lines( mydate_z0[, colum.x], mydate_z0[,colum.y], type<-"p",pch=2,cex=cex.point)
xspline(mydate_z0[, colum.x], mydate_z0[,colum.y], 0.2)
lines( mydate_f10[,colum.x],mydate_f10[,colum.y],type<-"p",pch=5,cex=cex.point)
xspline(mydate_f10[,colum.x],mydate_f10[,colum.y],0.2)
lines( mydate_f20[,colum.x],mydate_f20[,colum.y],type<-"p",pch=6,cex=cex.point)
xspline(mydate_f20[,colum.x],mydate_f20[,colum.y],0.2)
lines( mydate_f30[,colum.x],mydate_f30[,colum.y],type<-"p",pch=8,cex=cex.point)
xspline(mydate_f30[,colum.x],mydate_f30[,colum.y],0.2)
axis(1,at=x.axis,labels=new.x.axis,lty=1,las=1,tck=0.0,font.axis=3,lwd=lwd.grid,padj=1)
axis(2,at=y.axis,labels=new.y.axis,lty=1,las=1,tck=0.0,font.axis=3,lwd=lwd.grid,padj=1)
axis(3,at=x.axis,labels=FALSE, tck=0.0, lwd=lwd.grid)
axis(4,at=y.axis,labels=FALSE, tck=0.0, lwd=lwd.grid)
grid(number.grid.major.x,number.grid.major.y,lty=1,lwd=2,col="black",equilogs=FALSE)
grid(number.grid.minor.x,number.grid.minor.y,lty=3,lwd=1,col="black",equilogs=FALSE)
legend(x.legend,y.legend,inset=0.5,picture.legend,pch=c(0,1,2,5,6,8),bg="white",cex=cex.legend)
par(oldpar)
dev.off()
}
floder.dir <- ""
file.f30 <- paste(floder.dir,"dzf30.dat",sep ="")
file.f20 <- paste(floder.dir,"dzf20.dat",sep ="")
file.f10 <- paste(floder.dir,"dzf10.dat",sep ="")
file.z00 <- paste(floder.dir,"dzz00.dat",sep ="")
file.z10 <- paste(floder.dir,"dzz10.dat",sep ="")
file.z20 <- paste(floder.dir,"dzz20.dat",sep ="")
mydate_f30 <- read.table(file.f30)
mydate_f20 <- read.table(file.f20)
mydate_f10 <- read.table(file.f10)
mydate_z0 <- read.table(file.z00)
mydate_z10 <- read.table(file.z10)
mydate_z20 <- read.table(file.z20)
alpha <- c(-10,-5,0,5,10,15,20,25)
nalpha <- expression(-10,-5,0,5,10,15,20,alpha)
cy<- c(-0.5,0,0.5,1.0,1.5,2.0)
ncy <- expression(-0.5,0,0.5,1.0,1.5,C[y])
cleg <-expression(delta[z]==20^degree,delta[z]==10^degree,delta[z]==0^degree,
delta[z]==-10^degree,delta[z]==-20^degree,delta[z]==-30^degree)
PictureLine(name.picture="cy-a.jpg",
x.limit=c(-10,25),
y.limit=c(-0.5,2.0),
x.legend=10,
y.legend=1.0,
cex.legend=2.5 ,
number.grid.major.x=7,
number.grid.minor.x=35,
number.grid.major.y=5,
number.grid.minor.y=25,
colum.x=8,
colum.y=1,
x.axis=alpha,
new.x.axis=nalpha,
y.axis=cy,
new.y.axis=ncy,
picture.legend=cleg)
生成的图片如下图所示:
这个代码主要是用来绘制风洞实验数据曲线,绘制不同升降舵偏度下的升力系数,力矩系数,升阻比随迎角的变化等等。