我有,我已經添加了小時到我的約會結束scale_x_date其他列或使用時間以及日期
數據的數據幀:
structure(list(date = c("2016-01-30 11", "2016-01-30 13", "2016-01-30 16",
"2016-01-30 18", "2016-01-30 21", "2016-01-31 2", "2016-01-31 5",
"2016-01-31 7", "2016-01-31 13", "2016-01-31 13"), Obs = c(9L,
15L, 15L, 16L, 15L, 16L, 15L, 16L, 14L, 9L), score = structure(c(3L,
1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 2L), .Label = c("1", "1.5", "2"
), class = "factor"), date2_1 = c("2016-01-30", "2016-01-30",
"2016-01-30", "2016-01-30", "2016-01-30", "2016-01-31", "2016-01-31",
"2016-01-31", "2016-01-31", "2016-01-31"), date2_2 = c(11L, 13L,
16L, 18L, 21L, 2L, 5L, 7L, 13L, 13L)), .Names = c("date", "Obs",
"score", "date2_1", "date2_2"), class = c("data.table", "data.frame"
), row.names = c(NA, -10L), .internal.selfref = <pointer: 0x00000000001f0788>)
我的情節是:
ggplot(data = tt, aes(date2_1, Obs, colour=score)) +
geom_point() +
scale_colour_discrete(drop=TRUE, limits = levels(t$score))
在另一個數據幀I只具有日期(這是當量在這個數據date2_1)和更改與as.Date
使得下列作品類:
ggplot(data = t, aes(date, Obs, colour=score)) +
geom_point() +
scale_x_date(date_breaks = "1 day", date_labels="%d") +
scale_colour_discrete(drop=TRUE, limits = levels(t$score))
我想對我展示了第一幅圖使用scale_x_date(date_breaks = "1 day", date_labels="%d")
,但在使用date2_1
代替date
規模。
額外:在我的示例數據中,更好的方法是使用scale從date
運行,但是這不是課程日期,因爲我將小時粘貼到它上面。這個數據框是另一個子集,我確實有一個日期時間列,其值爲2016-01-30 11:50:52
,它們是POSIXct
,如果這有幫助的話 - 實際上我使用cSplit
,然後粘貼來獲取我的日期樣本數據。使用as.POSIXct
或strptime
我無法創建一個只有一小時的日期,或者如果我沒有scale_x_date
就不能使用它。
本質上我有一個只能縮放井的日期的情節,但是在使用日期和小時時,日期時間均勻分佈在x軸上,而不考慮日期和小時。
對這兩個選項的答案將不勝感激!
不知道爲什麼我沒有看到之前scale_x_datetime。 TY – Olivia