52

使用 R 中的基本图形,如何在轴标签上添加上标,就像在地图上绘制纬度和经度轴时可能想要的那样。

考虑这个例子:

plot(-100:-50, 50:100, type="n", xlab="", ylab="", axes=FALSE)
axis(1, seq(-100, -50, 10), labels=paste(abs(seq(-100, -50, 10)), "o", "W", sep=""))
axis(2, seq(50, 100, 10), labels=paste(seq(50,100,10), "o", "N", sep=""))
box()

在地图周围产生一个漂亮的框架。将度数符号设为上标会更好。

这通常可以在其他绘图功能中完成,例如mtext()text()使用expression(paste(...)),或者substitute()在这种情况下如何做到这一点?

4

4 回答 4

49

它对轴的工作方式相同:parse(text='70^o*N')将提高o作为上标(这*N是为了确保 N 也不会被提高)。

labelsX=parse(text=paste(abs(seq(-100, -50, 10)), "^o ", "*W", sep=""))
labelsY=parse(text=paste(seq(50,100,10), "^o ", "*N", sep=""))
plot(-100:-50, 50:100, type="n", xlab="", ylab="", axes=FALSE)
axis(1, seq(-100, -50, 10), labels=labelsX)
axis(2, seq(50, 100, 10), labels=labelsY)
box()
于 2012-05-17T00:59:06.983 回答
39

这是一个简单的例子

plot(rnorm(30), xlab = expression(paste("4"^"th")))
于 2012-05-17T01:04:20.603 回答
4

@The Thunder Chimp You can split text in such a way that some sections are affected by super(or sub) script and others aren't through the use of *. For your example, with splitting the word "moment" from "4th" -

plot(rnorm(30), xlab = expression('4'^th*'moment'))
于 2017-08-25T12:45:17.787 回答
3

在这种特殊情况下,另一个选项是输入度数符号:˚

R似乎处理得很好。在 Mac 上键入 Option-k 以获取它。不确定其他平台。

于 2014-04-16T05:33:04.230 回答