R_Plot_Marginの処理 - アールメカブ

アールメカブ


R_Plot_Marginの処理

Rの備忘録

# 『R の基礎とプログラミング技法』p.169

# 四つの外部マージンを3 行分の高さに設定

par(oma = rep(3, 4), bg = "gray")
plot(c(0, 1), c(0, 1), type="n", ann = FALSE, axes = FALSE)
par(xpd = TRUE) # 作図領域に加工を加える

# 作図領域を黄色に塗る

rect(par()$usr[1] - par()$mai[2], par()$usr[3] - par()$mai[1],
par()$usr[2] + par()$mai[4], par()$usr[4] + par()$mai[3],
col = "yellow", border = NA)
box("figure") # 作図領域全体を黒枠で囲む
par(xpd = FALSE) # 描画の対象をプロット領域に戻す

# プロット領域を白く塗りつぶす

rect(par()$usr[1], par()$usr[3],
par()$usr[2], par()$usr[4],
col = "white", border = NA)
box("plot", lty = "dashed", col = "green") # プロット領域を囲む
text(.5, .5, "plot region", cex = 1.6)

# 四つの内部マージンに描画

mtext("figure region", side = 3, line = 2, adj = 1, cex = 1.4)

# line = 2 は内部マージン上(side=3) の 2 行目の高さに描くことを指定

# adj は 0 なら左端,1 なら右端に描画.

for (i in 1:4)
mtext(paste("inner margin", i), side = i,
las = 0, line = 1, outer = FALSE)

# 四つの外部マージンに描画# outer = TRUE

for (i in 1:4)
mtext(paste("outer margin", i), side = i,
las = 0, line = 1, outer = TRUE)

# 外部マージンにラベルを付ける

mtext("device region", side=3, line=2, outer = TRUE, adj = 1, cex = 1.2)

# 最後にプロット全体を赤い枠で囲む

box("outer", col = "red", lwd = 3)

# axis(1) # これまで作成した図と重なるが,x 軸の目盛を描く

# axis(2) # y 軸の目盛を描く

dev.off()

ここではoma を使って外部マージン(outer margin) を行の高さを基準にしているが,omi を使えばインチで指定もできる.同じようにmar が(内部) マージンを行の高さで,mai がインチで指定するものである.

 
Link: R_old_tips2(1739d) Rの備忘録(3776d) 日録2007_11月(5985d)
Last-modified: 2007-11-07 (水) 17:51:32 (6009d)