0
考慮以下情節:圖不啓動在正確的x軸的刻度
x <- seq(from = 1.01, to = 1.05, by = 0.01) ## test
pmt_test = data.frame(Amount = c(paste(0.01, sep = " * "), paste(0.02, "r", sep = " * ")), Start = c(2,4), End = c(4,4))
p = paste("(", pmt_test$Amount, " * (i %in% ", pmt_test$Start, ":", pmt_test$End, "))", collapse = " + ")
res = Reduce(function(r, i) { (r + eval(parse(text = p))) * x[i] }, seq_along(x), init = 100, accumulate = TRUE)[-1]
par(xaxs='i',yaxs='i')
plot(res, type = "l", xaxt = 'n')
x.labels = paste("Year", 0:4, sep=" ")
axis(1, at = 0:4, labels=x.labels)
我獲得1年開始並延伸超過4年的預期圖,我的陰謀尋找應該從0年開始,結束於4年。似乎數據被移動並且不在x軸的右側點開始。
任何方式來解決? 謝謝!
當你調用'plot'時,指定'xlim'從0開始。 'xlim = c(0,_the maximum_)' –
在'axis'調用中更改'at = 1:5'。 R中的矢量索引是基於1的。 – James
@alexis_laz我已經嘗試設置xlim,它不能解決問題! – Mayou