[英]Plotting time vs duration in R
我正在嘗試在R中繪制時間與持續時間散點圖,但是遇到了不確定的問題,我不確定如何解決,或者問題是否出在我的data.frame中。
我嘗試瀏覽本網站上的其他示例以及其他示例,但沒有找到我想要的內容。
我的data.frames看起來像:
dput(head(departure.time))
structure(list(V1 = structure(c(35L, 36L, 5L, 6L, 7L, 8L), .Label = c("0:00",
"0:30", "1:00", "1:30", "10:00", "10:30", "11:00", "11:30", "12:00",
"12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30",
"16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00",
"19:30", "2:00", "2:30", "20:00", "20:30", "21:00", "21:30",
"22:00", "22:30", "23:00", "23:30", "9:00", "9:30"), class = "factor")), .Names = "V1", row.names = c(NA,
6L), class = "data.frame")
dput(head(travel.time))
structure(list(V1 = c(490L, 492L, 485L, 486L, 483L, 488L)), .Names = "V1", row.names = c(NA,
6L), class = "data.frame")
我不確定為什么travel.time在顯示36磅時僅顯示6個條目,而department.time幀也是如此
另外,我嘗試的代碼是
plot(departure.time, travel.time, main="Variable Travel Time", xlab="Departure Time", ylab="Travel Time in Minutes", pch=19)
但是我收到了錯誤
Error in xy.coords(x, y, xlabel, ylabel, log) :
“ x”和“ y”的長度不同
有什么建議嗎?
編輯您的代碼以:
plot(departure.time$V1, travel.time$V1, main="Variable Travel Time", xlab="Departure Time", ylab="Travel Time in Minutes", pch=19)
read.table
輸出一個data.frame
(請參閱help(read.table)
中的section value ),因此您需要告訴plot
在每個數據幀中使用哪一列。
如果您希望將departure.time
時間作為向量而不是數據幀,則應使用scan
而不是read.table
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.