有没有办法在 R 图中为 y 轴创建多线标签?
我尝试在换行符所在的位置添加
\n
,但标签的第一行被剪掉:
l <- 10
plot(0:l, (0:l), type='l',
yaxt='n',
xlab='Index',
ylab='Cumulative sum\nof the sorted weights')
这种情况在
tikzDevice
和 RStudio 内部都会发生。另外,我尝试了一些par()
选项,但没有成功。怎样做才是正确的呢?
(过大的上边距也让我烦恼......)
您需要使用
mar
或 mgp
设置边距:
l <- 10
op <- par(mar=c(5, 6, 4, 2) + 0.1)
plot(0:l, (0:l), type='l',
yaxt='n',
xlab='Index',
ylab='Cumulative sum\nof the sorted weights')
par(op)
就像 @smillig 建议的那样,您可以使用
par
来完成此操作,更改 mar
或 mgp
参数。
但是你必须先打电话
par
然后打电话给plot
。
允许完全控制轴标题的替代方法是使用
mtext()
。
l <- 10
plot(0:l, (0:l),
type = "l",
yaxt = "n",
xlab = "Index",
ylab = ""
)
mtext(side = 2, line = 3, "Cumulative sum")
mtext(side = 2, line = 2, "of the sorted weights")
创建于 2023-10-06,使用 reprex v2.0.2