Reputation: 3
I'm trying to plot a time vs duration scatterplot in R but encountered problems which I am not sure how to solve or if the problem lies in my data.frame.
I've tried looking through other examples on this website and others but haven't found what I'm looking for.
My data.frames look like :
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")
I'm not sure why my travel.time is showing only 6 entries when it has 36 obs as does the departure.time frame
Additionally, the code i tried was
plot(departure.time, travel.time, main="Variable Travel Time", xlab="Departure Time", ylab="Travel Time in Minutes", pch=19)
But i received the error
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
Any advice?
Upvotes: 0
Views: 198
Reputation: 17412
Edit your code to:
plot(departure.time$V1, travel.time$V1, main="Variable Travel Time", xlab="Departure Time", ylab="Travel Time in Minutes", pch=19)
read.table
outputs a data.frame
(see help(read.table)
, section value), so you need to tell plot
which column to use from each data frame.
If you want departure.time
to be a vector and not a dataframe, you should use scan
instead of read.table
.
Upvotes: 1