更改图例边框和图例标题之间的间距
Change spacing between legend border and legend title
我正在尝试使用 RStudio 将绘图保存为图元文件 (*.emf)。该图的格式在 *.emf 文件中看起来没问题,只是图例的上边框和图例标题之间没有间隙。我怎样才能增加这样的差距?我正在使用基础 R
.
这是代码。我无法将 *.emf 文件上传到 Stack Overflow。
cov <- 1:20
B0.1 <- 0.2
B1.1 <- 0.2
B0.2 <- -0.2
B1.2 <- 0.1
B0.3 <- -0.6
B1.3 <- -0.02
y.1 <- exp(B0.1 + B1.1 * cov) / (1 + exp(B0.1 + B1.1 * cov))
y.2 <- exp(B0.2 + B1.2 * cov) / (1 + exp(B0.2 + B1.2 * cov))
y.3 <- exp(B0.3 + B1.3 * cov) / (1 + exp(B0.3 + B1.3 * cov))
par(mfrow=c(1,1), pty="s")
plot(cov, y.1, bty = "l", type = 'l', col = 'black', lwd = 2, lty = 1,
xlab = 'Cov', ylab = 'Probability', ylim=c(0,1))
lines(cov, y.2, type = 'l', col = 'black', lwd = 2, lty = 2)
lines(cov, y.3, type = 'l', col = 'black', lwd = 2, lty = 3)
abline(v = 10, lwd = 2, lty = 6)
title('My Plot')
op <- par(cex = .67)
legend("bottomright", c('Prob 1', 'Prob 2', 'Prob 3'),
col = c("black", "black", "black"),
lty = c(1, 2, 3),
lwd = c(2, 2, 2),
y.intersp = c(1.5, 1.5, 1.5),
title = "Legend", cex = 1.00, text.width = 2.50)
之后用你自己的位置打印图例的边框:
先一个没有边框的图例(设置bty
为"n"),保存位置在"a":
a <- legend("bottomright",c('Prob 1', 'Prob 2', 'Prob 3'),
col = c("black", "black", "black"),
lty = c(1, 2, 3),bty="n",
lwd = c(2, 2, 2),
y.intersp = c(1.5, 1.5, 1.5),
title = "Legend", cex = 1.00, text.width = 2.50)
定义你自己的矩形位置:
rect(a$rect$left, a$rect$top-a$rect$h[1], a$rect$left+a$rect$w, a$rect$h[1])
我正在尝试使用 RStudio 将绘图保存为图元文件 (*.emf)。该图的格式在 *.emf 文件中看起来没问题,只是图例的上边框和图例标题之间没有间隙。我怎样才能增加这样的差距?我正在使用基础 R
.
这是代码。我无法将 *.emf 文件上传到 Stack Overflow。
cov <- 1:20
B0.1 <- 0.2
B1.1 <- 0.2
B0.2 <- -0.2
B1.2 <- 0.1
B0.3 <- -0.6
B1.3 <- -0.02
y.1 <- exp(B0.1 + B1.1 * cov) / (1 + exp(B0.1 + B1.1 * cov))
y.2 <- exp(B0.2 + B1.2 * cov) / (1 + exp(B0.2 + B1.2 * cov))
y.3 <- exp(B0.3 + B1.3 * cov) / (1 + exp(B0.3 + B1.3 * cov))
par(mfrow=c(1,1), pty="s")
plot(cov, y.1, bty = "l", type = 'l', col = 'black', lwd = 2, lty = 1,
xlab = 'Cov', ylab = 'Probability', ylim=c(0,1))
lines(cov, y.2, type = 'l', col = 'black', lwd = 2, lty = 2)
lines(cov, y.3, type = 'l', col = 'black', lwd = 2, lty = 3)
abline(v = 10, lwd = 2, lty = 6)
title('My Plot')
op <- par(cex = .67)
legend("bottomright", c('Prob 1', 'Prob 2', 'Prob 3'),
col = c("black", "black", "black"),
lty = c(1, 2, 3),
lwd = c(2, 2, 2),
y.intersp = c(1.5, 1.5, 1.5),
title = "Legend", cex = 1.00, text.width = 2.50)
之后用你自己的位置打印图例的边框:
先一个没有边框的图例(设置bty
为"n"),保存位置在"a":
a <- legend("bottomright",c('Prob 1', 'Prob 2', 'Prob 3'),
col = c("black", "black", "black"),
lty = c(1, 2, 3),bty="n",
lwd = c(2, 2, 2),
y.intersp = c(1.5, 1.5, 1.5),
title = "Legend", cex = 1.00, text.width = 2.50)
定义你自己的矩形位置:
rect(a$rect$left, a$rect$top-a$rect$h[1], a$rect$left+a$rect$w, a$rect$h[1])