[英]Plot timeseries in R with base graph system
我需要這樣的繪圖,我有日期和時間列,我只能使用 R 的基本繪圖系統
我想
GPA = data[, "GPA"]
data[, "Date"] = as.Date(data[,"Date"])
time = paste(data[, "Date"], data[, "Time"])
time = strftime(time, format = "%a %H:%M:%S")
plot(time, GPA)
它給了我:
plot.window(...) 中的錯誤:需要有限的“xlim”值
此外: 警告消息:
1: 在 xy.coords(x, y, xlabel, ylabel, log) : 由強制引入的 NAs
2:在 min(x) 中:沒有非缺失的 min 參數; 返回信息
3:在 max(x) 中:沒有非缺失的 max 參數; 返回 -Inf
如果您正在處理時間序列,則 lubridate 包很棒。
但展示了一個僅使用基礎 R 的過程。
以“dt.raw”的形式讀取數據,通常最好不要使用屏蔽基本函數的名稱。
set.seed(1234) # so you get the same results I do
mydata <- dt.raw[sample(nrow(dt.raw), 10000),] # only using a subset of your data
colnames(mydata)[3] ="GAP"
mydata$Date = as.Date(mydata$Date, format = "%d/%m/%Y") # just the date part
mydata$datetime = paste(mydata$Date, mydata$Time) # concatenating
mydata$datetime = as.POSIXct(mydata$datetime, format = "%Y-%M-%d %H:%M:%S") # Converting to time format
mydata <- mydata[order(mydata$datetime),] # Sorting by the date time for future line plotting
plot(mydata$datetime, mydata$GAP)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.