-1
下の例の最後の行では、pos
のいくつかの異なる値を手作業で試してから、前の行に既にプロットされていたlabels
です。適切な値pos
を自動的に見つける方法はありますか?軸ラベルをプロットするための 'pos'の値を自動的に調べる
dev.off()
windows(width = 8, height = 6)
par(mai = c(0.3, 2.5, 0.3, 0.3)) #bottom, left, top and right
set.seed(42)
plot(rnorm(15,10,1),rnorm(15,10,1), type = "p",
ylim = c(5,15), xlim = c(5,15), xlab = "", ylab = "",
xaxt = "n", yaxt = "n", yaxs="i", xaxs="i")
axis(2, at = c(5,10,15), labels = c("This one", "Particularly long one", "two"), las = 2)
axis(2, at = 10, pos = 2, labels = "Y Axis Label", font = 2, tick = FALSE, cex.axis = 1.5)
@DarshanBaral確かに、 'max'、' which.max'、または 'which'のいくつかの組み合わせが役に立つはずです。 'max(strwidth(label_variable))'が最大値をとり、 'strwidth(label_variable)== max(strwidth(label_variable))'が最大値を通知します。 – Jota