用自己的值替换 X 轴

我有一个关于指挥图的问题。

有没有办法完全消除 x 轴并用自己的值替换它?我知道我可以通过做

plot(x,y, xaxt = 'n')

and then add an axis with

axis(side = 1 etc.)

However, when I add the axis, obviously it still refers to the data plotted as 'x'. 我只想绘制‘ y’值,并添加我自己的 x 轴,这意味着仅仅“绘制”指定了自己值的 x 轴。有什么办法吗?

这个问题的背景是,我的两个数据帧的长度不同,因此我不能绘制它们。

370962 次浏览

不知道你是不是这个意思,但你可以这样做:

plot(1:10, xaxt = "n", xlab='Some Letters')
axis(1, at=1:10, labels=letters[1:10])

然后给出图表:

enter image description here

You could set labels = FALSE inside axis(...) and then print the labels in a separate command using text(...). This option would allow you to rotate the text in case you need it.

lablist<-as.vector(c(1:10))
axis(1, at=seq(1, 10, by=1), labels = FALSE)
text(seq(1, 10, by=1), par("usr")[3] - 0.2, labels = lablist, srt = 45, pos = 1, xpd = TRUE)

详细说明

Image with rotated labels