0
我有一個數據庫與日期(數據$時間)和數值(數據$ ert)的變量。我是R新手,想要學習(在這裏檢查了很多鏈接,在Google上;也使用了?geom_rect),可能這是一個愚蠢的問題。如何在使用日期變量作爲x軸時使用geom_rect [R]?
library(ggplot2)
data<-read.csv("pt1.csv", header=T, sep="\t", dec=",")
data$time<-as.Date(data$time, "%d/%m/%y", origin="1970-01-01")
pt1.plot<-<-ggplot(data, aes(time, ert, group=1, na.rm=T))+geom_rect(aes(xmin=2, xmax=Inf, ymin=-Inf, ymax=Inf), fill="lightgreen", alpha=0.03)+geom_line()+labs(x="", y="ert")+geom_hline(aes(yintercept=0.5), colour="#990000", linetype="dashed")
pt1.plot
當試圖想象它給了我這個錯誤的情節:
Error in as.Date.numeric(value) : 'origin' must be supplied
我不明白如何提供原產地信息到geom_rect。 有什麼問題?
謝謝,它的工作!有沒有辦法計算出對應某個日期的數字?否則,我將不得不嘗試數字,並與情節的視覺控制。 – Raphus
你可以嘗試'as.numeric(as.Date(「yourdate」,「%d /%m /%y」,origin = as.Date(「1970-01-01」)))' – Craig
回答你的問題,請接受答案來結束這個問題! – Craig