Reputation: 6766
I have data as below. I want to plot series y1 and y2 in different color lines and x axis labels should be values from variable x1. I am getting an error :(
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
i would prefer if first 2 x axis labels come from x1 and third one is M. Something like c(x[1:2],"M")
...how could I put custom labels?
Upvotes: 0
Views: 138
Reputation: 6222
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)
#
Is this what you are after?
plot(y1, xaxt='n', type="l")
axis(side = 1, at = 1:3, labels = c(x1[1:2],"M"))
I think you have to specify values at
where your labels
should go. Above works.
Upvotes: 1