2013-07-31 82 views
1

我有一個數據幀df,其中包含R日期對象的列time,我想繪製一個密度圖以查看哪些日子的活動最多。我不想轉換爲時間戳,因爲我希望在x軸上使用更多有意義的標籤。如何在ggplot2中使用x軸上的日期製作密度圖

我嘗試

這裏就是我想:

ggplot(df, aes(x = time)) + geom_density(stat="identity") + scale_x_date() 

這給錯誤

Error in as.environment(where) : 'where' is missing 

這裏是dput(df)輸出:

structure(list(time = structure(c(15863, 15887, 15865, 15873, 15885, 15878), class = "Date")), .Names = "time", row.names = 8831395:8831400, class = "data.frame") 
+1

你能告訴'dput(DF)'(或者'dput(頭(DF))'如果它很大?) –

+0

完成,參見上文。 – Peteris

回答

3

出於某種原因,stat_density的參數導致ggplot在設置的環境中失去它的方式。 (至少這是在 「裏」 失蹤錯誤的由來。)這個成功:

ggplot(df, aes(x = time)) + geom_density() 

enter image description here

相關問題