[英]r plotting multiple series and custom x axis labels
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.
我想以不同的颜色线绘制系列y1和y2,并且x轴标签应为变量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? 如果第一个2 x轴标签来自x1,第三个是M,我会更喜欢。像
c(x[1:2],"M")
...如何放置自定义标签?
eidt: 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. 我认为您必须
at
labels
应该去的地方指定值。 Above works. 以上作品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.