你的數據集是不完整的,但你可以從下面的範例中得到啓發:
ggplot(df, aes(x=Time, y=Speed, group=Cars, color=Cars)) + geom_line() +
scale_colour_manual(values=c("blue", "green", "yellow"))
數據:
這與您的數據不同(它有不同的列),但看起來像它。
df <- structure(list(Cars = structure(c(3L, 2L, 3L, 1L, 2L, 1L), .Label = c("BlueCar",
"Greencar", "YellowCar"), class = "factor"), Date = structure(c(1L,
1L, 1L, 1L, 1L, 2L), .Label = c("2017-07-08", "207-07-08"), class = "factor"),
Time = structure(c(6L, 1L, 2L, 3L, 4L, 5L), .Label = c("05:01:35",
"05:03:31", "05:52:55", "10:21:57", "12:07:51", "17:41:00"
), class = "factor"), Speed = c(20L, 30L, 10L, 4L, 2L, 15L)),
.Names = c("Cars", "Date", "Time", "Speed"), class = "data.frame", row.names = c(NA,-6L))
老兄,這真棒幫助!還有一個問題,如果我想在x軸中表示日期和時間,該怎麼辦?我偶然發現as.POSIXlt似乎採用這種UTC格式,我如何在這裏實現它? – AnthonyM
@AnthonyM添加這個'+ scale_x_datetime(breaks = Date,labels = format(Date,「%Y-%m-%d%H:%M:%S」)' – Masoud