我有一個數據集,它包含以下日期變量。處理ggplot2中罕見的日期結構
dat$Leads_MONTH
[1] "10-Jan" "10-Feb" "10-Mar" "10-Apr" "10-May" "10-Jun" "10-Jul" "10-Aug" "10-Sep" "10-Oct" "10-Nov" "10-Dec" "11-Jan" "11-Feb" "11-Mar" "11-Apr"
[17] "11-May" "11-Jun" "11-Jul" "11-Aug" "11-Sep" "11-Oct" "11-Nov" "11-Dec" "12-Jan" "12-Feb" "12-Mar" "12-Apr" "12-May" "12-Jun" "12-Jul" "12-Aug"
[33] "12-Sep" "12-Oct" "12-Nov" "12-Dec" "13-Jan" "13-Feb" "13-Mar" "13-Apr" "13-May" "13-Jun" "13-Jul"
我想使用ggplot2在x軸上繪製這些數據,但是我在這個任務中遇到了一些問題。有沒有辦法讓ggplot2格式化Leads_MONTH作爲日期格式,然後使用ggplot2來繪製它。
ggplot(dat, aes(Leads_MONTH, LEADSforester)) +
geom_bar(stat="identity", fill="#336699") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
上面的代碼會生成一個圖表,但x軸上的日期不在寫入順序中。
我試圖設置變量作爲日期,但沒有任何運氣。
> dat$Leads_MONTH <- as.Date(dat$Leads_MONTH)
Error in charToDate(x) :
character string is not in a standard unambiguous format
還要注意的是動物園裏有'scale_x_yearmon()' –