par(……,no.readonly=FALSE)
參數(shù):
..arguments in tag = value form, or a list of tagged values. The tags must come from the names of graphical parameters described in the ‘Graphical Parameters’ section.(圖形參數(shù)選項(xiàng),一般用tag=value或向量形式展示,如col="black")
no.readonlylogical; if TRUE and there are no other arguments, only parameters are returned which can be set by a subsequent par() call?on the same device.(如取值為TRUE,則可修改當(dāng)前圖形中的參數(shù))
圖形參數(shù):
1、關(guān)于顏色
bg:背景色(在繪圖函數(shù)中為圖形填充色,在par函數(shù)中為整個(gè)圖形的背景色)??fg:前景色 col:圖形顏色,一般用法:col=1,或col="red",或col=rgb(1,1,1),或col=hsv(0,0,1)
col.axis:坐標(biāo)軸刻度文字顏色??col.main:主標(biāo)題顏色??col.sub:副標(biāo)題顏色? ?col.lab:標(biāo)簽顏色
code及示例:
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
opar<-par(bg="gray",no.readonly = TRUE)
layout(matrix(c(1,2,3,4,5,6,7,7,7),3,3,byrow = TRUE))
plot(dose,drugA,type="p",main = "type=p")
plot(dose,drugA,type="l",fg="orange",main = "type=l and fg=orange")
plot(dose,drugA,type="b",col="orangered",main = "type=b and col=orangered")
plot(dose,drugA,type="c",col.axis="yellow",main = "type=c and col.axis=yellow")
plot(dose,drugA,type="o",col.lab="red",main = "type=o and col.lab=red")
plot(dose,drugA,type="h",col.main="red",main = "type=h")
plot(dose,drugA,type="s",col.sub="green",main = "type=s",sub = "sub=green")

2、關(guān)于字體
family :全局字體,特指字體的類型,標(biāo)準(zhǔn)取值:serif,sans,mono?
font :字體,特指字體的形態(tài),如斜體還是粗體(1:常規(guī),2:粗體,3:斜體,4:粗斜體,5:符號(hào)字體)
font.axis:坐標(biāo)軸刻度字體? ?font.lab:坐標(biāo)軸標(biāo)簽字體? ?font.main:主標(biāo)題字體??font.sub:副標(biāo)題字體
code及示例:
opar<-par(bg="gray",no.readonly = TRUE)
par(mfrow=c(2,1))
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
drugB<-c(15,18,25,31,40)
par(family="mono") #mono字體
plot(dose,drugA,type="p")
title(main="family arial style",
sub="clinical trials for drugA ")
par(family="")#默認(rèn)字體
plot(dose,drugA,type="l",fg="orange")
title(main="type=l and fg=orange",sub = "clinical trials for drugA ")
par(opar)

3、關(guān)于大小
cex:相對(duì)于圖形默認(rèn)大小縮放倍數(shù)的數(shù)值。默認(rèn)值為1,1.5為放大默認(rèn)值的1.5倍,0.5為縮小默認(rèn)值的50%;
cex.axis:坐標(biāo)軸字體縮放倍數(shù);??cex.lab:坐標(biāo)軸標(biāo)簽縮放倍數(shù)? ?cex.main:主標(biāo)題縮放倍數(shù)
cex.sub:副標(biāo)題縮放倍數(shù)
ps:字體磅值(文本最終磅值為ps*cex)
code及示例:
opar<-par(no.readonly = TRUE)
par(mfrow=c(2,1))
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
#默認(rèn)狀態(tài)
par(family="mono")
plot(dose,drugA,type="p")
title(main="family arial style",
sub="clinical trials for drugA ")
#字體縮放
par(family="mono")
par(cex.axis=1.5,cex.lab=2,cex.sub=1.5,cex.sub=0.8,ps=10)
plot(dose,drugA,type="p")
title(main="family arial style",
sub="clinical trials for drugA ")
par(opar)

4、關(guān)于線條及符號(hào)
pch:??繪制點(diǎn)時(shí)使用的符號(hào)??lty:指定線條類型? ?lwd:線條寬度(默認(rèn)值1,lwd=2表示為默認(rèn)值的2倍)
附:


code及示例
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
par(family="mono")
plot(dose,drugA,type="b",pch=21,col="red",bg="orange",lty=3,lwd=2,main="family arial style",
sub="clinical trials for drugA ",cex.axis=1.5,
cex.lab=2,cex.sub=1.5,cex.sub=0.8,ps=10)

5、關(guān)于坐標(biāo)軸,及其標(biāo)簽、范圍(1)xlab及ylab: x、y軸的標(biāo)簽,可改變默認(rèn)值? ???xlim:x軸數(shù)據(jù)范圍如xlim=c(0,60)??ylim:y軸數(shù)據(jù)范圍如ylim=c(0,70)(2)axis(side,at=,labels=,pos=,lty=,col=,las=,tck=,outer=,font=,lty=,lwd=,lwd.tick=,col=,col.tick=,……)
side:整數(shù),表示在圖形的哪邊繪制坐標(biāo)軸(1=下,2=左,3=上,4=右)
at:數(shù)值型向量,表示需要繪制刻度線的位置
labels:坐標(biāo)軸刻度線旁的文字標(biāo)簽,如為NULL,則將使用at中的值;
pos:坐標(biāo)軸線繪制位置的坐標(biāo)(即與另一條坐標(biāo)軸線相交位置的值);
las:標(biāo)簽是否平行于(=0)或垂直于(=2)坐標(biāo)軸;
tck:刻度線長(zhǎng)度(負(fù)值表示在圖形外側(cè),正值表示在圖形內(nèi)側(cè),0表示禁用刻度,1表示繪制網(wǎng)格線,默認(rèn)值為-0.01)(3)次要刻度線(Hmisc包對(duì)于最新的r版本已不適用)
code及示例(1)
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
par(family="mono")
plot(dose,drugA,type="b",pch=21,col="red",bg="orange",lty=3,lwd=2,main="family mono style",
sub="clinical trials for drugA ",xlab="dosage",ylab="drug reponse",xlim=c(0,60),ylim=c(0,70)
,cex.axis=1.5,cex.lab=2,cex.sub=1.5,cex.sub=0.8,ps=10)

(2)
opar<-par(no.readonly = TRUE)
par(mar=c(5,4,4,8)+0.1)
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
drugB<-c(15,18,25,31,40)
plot(dose,drugA,type = "b",pch=21,cex=0.5,col="red",xaxt="n",bg="red",lty=3,lwd=2,ann = FALSE)
lines(dose,drugB,type = "b",pch=22,cex=0.6,col="orangered",bg="orangered",lty=3)
axis(1,at=dose,label=dose,col.axis="red",las=0,tck=-0.01)
axis(4,at=drugB,labels = drugB,col.axis="blue",las=2,tck=-0.01)
mtext("drugB",side=4,line=3,las=2,col="blue")
title("An example of drug respose", xlab=" dose value",ylab="drugA")
par(opar)

6、關(guān)于圖形尺寸及邊界mai:設(shè)定圖形四周的空白尺寸,單位是英寸,以mai=c(bottom,left,top,right)形式使用;

mar:同mai,設(shè)定圖形四周的空白尺寸,以mar=c(bottom,left,top,right)形式使用,默認(rèn)為mar=c(5,4,4,2)+0.1;
oma:設(shè)定文本四周的空白區(qū)域,以oma=c(bottom,left,top,right)形式使用,如下圖:

omi:同oma,但單位是英寸;
omd:設(shè)定坐標(biāo)軸內(nèi)圖形距離坐標(biāo)軸的空白區(qū)域參數(shù),以omd=c(x1,x2,y1,y2)形式使用;
code及示圖:
opar<-par(no.readonly = TRUE)
par(mai=c(1,1,1,2))
dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
drugB<-c(15,18,25,31,40)
plot(dose,drugA,type = "b",pch=21,cex=0.5,col="red",xaxt="n",bg="red",lty=3,lwd=2,ann = FALSE)
lines(dose,drugB,type = "b",pch=22,cex=0.6,col="orangered",bg="orangered",lty=3)
axis(1,at=dose,label=dose,col.axis="red",las=0,tck=-0.01)
axis(4,at=drugB,labels = drugB,col.axis="blue",las=2,tck=-0.01)
mtext("drugB",side=4,line=3,las=2,col="blue")
title("An example of drug respose", xlab=" dose value",ylab="drugA")
par(opar)

7、關(guān)于多圖形布局
(1)mfrow=c(nrows,ncols)按行填充的、行數(shù)為nrows、列數(shù)為ncols的圖形矩陣;
(2)nfcol=c(nrows,ncols)按列填充矩陣;
(3)layout(mat, widths = rep.int(1, ncol(mat)),heights = rep.int(1, nrow(mat)), respect = FALSE)
? ?mat:矩陣,用以指定圖形繪制的位置;
? ?widths:各列寬度值組成的一個(gè)向量;
? ?heights:各行高度值組成的一個(gè)向量;(相對(duì)寬度可以通過數(shù)值直接指定,絕對(duì)寬度通過lcm()來指定)布局解析請(qǐng)參見:http://blog.sina.com.cn/s/blog_5de124240101pxvm.html
(4)fig=c(x1,x2,y1,y2)具體意義如下:

code及圖形示例dose<-c(20,30,40,45,60)
drugA<-c(16,20,27,40,60)
drugB<-c(15,18,25,31,40)
par(fig=c(0,0.8,0,0.8),new=FALSE)
plot(dose,drugA,type = "b",pch=21,cex=0.5,col="red",xaxt="n",bg="red",lty=3,lwd=2,ann = FALSE)
lines(dose,drugB,type = "b",pch=22,cex=0.6,col="orangered",bg="orangered",lty=3)
par(fig=c(0,0.8,0.69,0.95),new=TRUE)
boxplot(drugA, horizontal=TRUE, axes=FALSE)
par(fig=c(0.7,0.95,0,0.8),new=TRUE)
boxplot(drugB, axes=FALSE)
mtext("An example of drug respose", side=3, outer=TRUE, line=-3)

8、關(guān)于圖例、文本及其他
(1)text(location,"text to place",pos,……)(2)mtext("text to place",side,line=n,……)

另:其他常用選項(xiàng)還有cex、col、font
(3)legend(location,title,legend,.....)

drugA<-c(16,20,27,40,60)
drugB<-c(15,18,25,31,40)
par(fig=c(0,0.8,0,0.8),new=FALSE)
plot(dose,drugA,type = "b",pch=21,cex=0.5,col="red",xaxt="n",bg="red",lty=3,lwd=2,ann = FALSE)
lines(dose,drugB,type = "b",pch=22,cex=0.6,col="orangered",bg="orangered",lty=3)
legend("topleft",inset = .05,title = "drug type",c("A","B"),lty = c(3,3),pch = c(21,22),col=c("red","red"))
par(fig=c(0,0.8,0.69,0.95),new=TRUE)
boxplot(drugA, horizontal=TRUE, axes=FALSE)
par(fig=c(0.7,0.95,0,0.8),new=TRUE)
boxplot(drugB, axes=FALSE)
mtext("An example of drug respose", side=3, outer=TRUE, line=-3)

9、關(guān)于par()的其他說明函數(shù)par()中的參數(shù)可以分為三大類:
(1)只能讀取,不能進(jìn)行設(shè)置。包括參數(shù)cin,cra,csi,cxy,din。
(2)只能通過函數(shù)par()進(jìn)行設(shè)置。包括參數(shù):"ask","fig","fin","lheight","mai","mar","mex","mfcol","mfrow","mfg","new","oma","omd","omi","pin","plt","ps","pty","usr","xlog","ylog"
(3)剩下的參數(shù)除了函數(shù)par()外,還可以通過各種高級(jí)繪圖函數(shù)進(jìn)行設(shè)置,如函數(shù)plot,points,lines,abline,title,text,axis,image,box,contour,rect,arrows等。



相關(guān)帖子
運(yùn)營(yíng)方向就業(yè)班,成為互聯(lián)網(wǎng)大廠需要的人寶潔圖形推理題
調(diào)節(jié)作用圖形解讀因子分析中的biplot圖形
plant simulation 圖形資料庫關(guān)于基金回撤圖形的問題
傾向匹配得分的圖形圖形編輯軟件labview應(yīng)用
9.png?(34.63 KB)
