在两行 (\n) 中的绘图下标不起作用

In plots subscripts in two lines (\n) not working

这个post已经很好地描述了如何写下标:Subscripts in plots in R

他们还解决了更复杂的问题,例如:

plot(1:10, xlab = expression('hi'[5]*'there'[6]^8*'you'[2]))

问题:分两行怎么写?使用 \n(换行)会导致奇怪的重新排序问题:

plot(1:10, xlab = expression('hi'[5]*'there'[6]^8*'you \n awesome people'[2]))

您不能将 plotmath 表达式与 "\n" 混合使用。但是,您可以使用 plotmath 命令 atop:

opar <- par(no.readonly = TRUE)
par(mar = c(7, 4, 4, 2) + 0.1,
    mgp = c(5, 1, 0))

plot(1:10, xlab=expression(atop('hi'[5] * 'there'[6]^8 * 'you', 'awesome people'[2])))

par(opar)

请注意我是如何添加 * 来并列不同文本的。您的尝试是无效的语法。你应该学习 help("plotmath").