我正在努力为我的abline画上标签:
我有以下程序:
plot(mydata$date, mydata$Standerton,
type = "l",
col="brown", ylim = c(0.0,300), xlab='', ylab='', axis = T)
par(new=T)
abline(h="191", col="red")
text(05-11-2017, 200, "hello", pos = 4, col = "red", cex = 0.9)
我的x轴标签是日期。格式为dd-mm-yy HM
。
答案 0 :(得分:0)
The main problem in your code is that you are passing 1st parameter as 05-11-2017
to the text
. It actually gets converted to a numeric (5-11-2017) => -2023
value which is not meaningful on x-axis.
The text
expect 1st parameter as co-ordinate on x-axis. In your case the value of x-axis is in date
. Hence, the 1st parameter to text
is expected of type date
. The correct syntax for text should be:
text(as.POSIXct("05-11-2017", tz="", format = "%d-%m-%Y"), 200, "hello",
pos = 4, col = "red", cex = 0.9)