繁体   English   中英

更改图例中的字体大小

[英]Change font-size in legend

我的情节中有一个图例,但我正在尝试增加字体大小以使其适合图例框。 当我尝试增加如下定义的cex 盒子变大了,而文本仍然很小。

代码:

legend(0,16, c("Available vCPUs", "Added vCPUs (1 per iteration ) "),
 col=c('red', 'black'), cex=0.39, lty=1:1, lwd=2)

情节摘录:

在此处输入图片说明

第一种方法:

尝试在绘制图例之前设置字体大小。

 x <- y <- rnorm(100, 0, 1)
 plot(x, y, type = "n")

## here you set the font size default to `x`, in this example 0.5
## save defaults in `op`

 op <- par(cex = 0.5)

 legend("topright", legend = "foo legend", pch = 1, bty = "n")

在此处输入图片说明

## here you set cexto 1.5
## save new defaults in `op`

 op <- par(cex = 1.5)

 legend("topright", legend = "foo legend", pch = 1, bty = "n")

在此处输入图片说明

第二种方法:

拿着pt.cex参数为1,而尝试不同的值cex传说调用 记得删除op

x <- rnorm(100, 10, 4)
y <- rnorm(100, 10, 4)
plot(x, y, type = "n")

## I tried to feed cex with 1.5 and 0.5. The font size changes while the points remain unchanged.

legend("topleft", "Legend", cex=0.5, pch=1, pt.cex = 1)

在此处输入图片说明

可以用cex确定字体大小,用bty='n'表示图例周围没有线条,然后用rect()在图形上单独画一个矩形。 例如:

with(data, legend(-10,7, legend=c("Name_of_Legend"), bty = 'n', col=c("red"), lty=0, pch=20, cex=0.75))
with(data, rect(-10,6.2,-3,7))

我认为您可以尝试使用y.intersp中的y.intersp ,当不同文本行之间的间隔减少时,您可以在不更改图例框大小的情况下增加文本大小。

legend(0,16, c("Available vCPUs","Added vCPUs (1 per iteration )
"),col=c('red','black'),cex=0.39,lty=1:1,lwd=2, y.intersp = 0.3)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM