我的数据如下。我想在不同的颜色线上绘制y1和y2系列,x轴标签应该是变量x1的值。我收到一个错误:(
x1=c("a","b","c")
y1=c(1,2,0)
y2=c(4,5,2)
plot(y1,xaxt='n',type="l")
axis(side = 1, at = x1,labels = T)
NAs introduced by coercionError in axis(side = 1, at = x1, labels = T) : no locations are finite
我更喜欢如果前2个x轴标签来自x1而第三个是M.我喜欢c(x[1:2],"M")
...我怎么能放自定义标签?
答案 0 :(得分:1)
eidt:
plot(1:3, y1, xaxt='n', type="l", ylim=range(c(y1, y2)))
points(1:3, y2, type = "l", col = "blue")
axis(side = 1, at = 1:3, labels = c(x1[1:2],"M"))
text(1:3, y1, y1)
text(1:3, y2, y2)
#
这就是你追求的吗?
plot(y1, xaxt='n', type="l")
axis(side = 1, at = 1:3, labels = c(x1[1:2],"M"))
我认为您必须指定at
应该去的值labels
。以上作品。