X 轴标签根据向量变化

X Axis Label Change according to vector

大家好久不见回来啦!!

我遇到了 atm 问题,你可以帮我解决。

我需要更改 X 轴索引,以便显示月份而不是显示数字

这就是我现在拥有的

这就是我想要的样子

这是我使用的代码。

mes_totales <- c(total_septiembre, total_octubre)
plot(mes_totales, main = "Ganancia x mes", xlab = "Mes", ylab = "Ganancia")

这是数据。

> print(mes_totales)
[1]  1260 11700
> names(mes_totales) <- c("septiembre", "octubre")
> print(mes_totales)
septiembre    octubre 
      1260      11700

谢谢大家!

你可以这样做:

plot(mes_totales, xaxt="n", xlab="Mes", main="Ganancia x mes", ylab="Ganancia")
axis(1, at=1:2, labels=c('"septiembre", "octubre")

您将 xaxt="n" 添加到绘图语句中。这允许您在下一个语句中定义自己的 x 轴。 x 轴为 1,如果您想定义 y 轴,您将使用 axis(2....)。它对我有用。