我想为我的特定目的编写一个绘图函数,并将 y 标签放在左边距。然而,这些标签的长度可能会有很大差异,并且取决于用户提出的模型术语。出于这个原因,我想测量最长标签的宽度并相应地设置左边距宽度。我找到了该strwidth
函数,但我不明白如何将其输出单位转换为mar
参数单位。一个例子:
label <- paste(letters, collapse = " ") # create a long label
par(mar = c(5, 17, 4, 2) + 0.1) # 17 is the left margin width
plot(1:2, axes = FALSE, type = "n") # stupid plot example
# if we now draw the axis label, 17 seems to be a good value:
axis(side = 2, at = 1, labels = label, las = 2, tck = 0, lty = 0)
# however, strwidth returns 0.59, which is much less...
lab.width <- strwidth(label) # so how can I convert the units?