A5C*_*2T1 47
这应该可行,但你需要使用line参数来使它恰到好处:
par(mfrow = c(2, 2))
plot(iris$Petal.Length, iris$Petal.Width)
plot(iris$Sepal.Length, iris$Petal.Width)
plot(iris$Sepal.Width, iris$Petal.Width)
plot(iris$Sepal.Length, iris$Petal.Width)
mtext("My 'Title' in a strange place", side = 3, line = -21, outer = TRUE)
Run Code Online (Sandbox Code Playgroud)

mtext代表"保证金文字".side = 3说把它放在"顶部"边缘.line = -21说要将展示位置抵消21行.outer = TRUE说使用外边缘区域是可以的.
要在顶部添加另一个"标题",您可以使用,例如,添加它 mtext("My 'Title' in a strange place", side = 3, line = -2, outer = TRUE)
Did*_*rts 32
您可以使用该功能layout()并设置两个列中出现的两个绘图区域(请参阅重复的数字1和3 matrix()).然后我用plot.new()和text()设置标题.您可以使用边距和高度来获得更好的表现.
x<-1:10
par(mar=c(2.5,2.5,1,1))
layout(matrix(c(1,2,3,4,1,5,3,6),ncol=2),heights=c(1,3,1,3))
plot.new()
text(0.5,0.5,"First title",cex=2,font=2)
plot(x)
plot.new()
text(0.5,0.5,"Second title",cex=2,font=2)
hist(x)
boxplot(x)
barplot(x)
Run Code Online (Sandbox Code Playgroud)

Ufo*_*fos 13
使用title(...)与上述相同的参数可以使用相同但粗体显示:
title("My 'Title' in a strange place", line = -21, outer = TRUE)
Run Code Online (Sandbox Code Playgroud)
这是另一种方法,使用这篇文章中的line2user函数.
par(mfrow = c(2, 2))
plot(runif(100))
plot(runif(100))
text(line2user(line=mean(par('mar')[c(2, 4)]), side=2),
line2user(line=2, side=3), 'First title', xpd=NA, cex=2, font=2)
plot(runif(100))
plot(runif(100))
text(line2user(line=mean(par('mar')[c(2, 4)]), side=2),
line2user(line=2, side=3), 'Second title', xpd=NA, cex=2, font=2)
Run Code Online (Sandbox Code Playgroud)

这里,标题位于比图的上边缘高2行的位置,如图所示line2user(2, 3).我们通过相对于第2和第4图偏移它,使左右边距的组合宽度的一半,即mean(par('mar')[c(2, 4)]).
line2user 表示用户坐标中轴的偏移量(行数),定义如下:
line2user <- function(line, side) {
lh <- par('cin')[2] * par('cex') * par('lheight')
x_off <- diff(grconvertX(0:1, 'inches', 'user'))
y_off <- diff(grconvertY(0:1, 'inches', 'user'))
switch(side,
`1` = par('usr')[3] - line * y_off * lh,
`2` = par('usr')[1] - line * x_off * lh,
`3` = par('usr')[4] + line * y_off * lh,
`4` = par('usr')[2] + line * x_off * lh,
stop("side must be 1, 2, 3, or 4", call.=FALSE))
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56069 次 |
| 最近记录: |