2016-11-09 35 views
1

當我繪製它時,我的直方圖看起來不像是在正確的日期。R中的直方圖和日期位置

我的數據是這樣的

date  tcol names 
2005-03-31 170 Site 4 
2005-03-31 328 Site 5 
2005-03-31 40  Site 6 

我的代碼看起來像

ggplot(data=allsite, aes(x=date, weight=tcol, colour=names, fill=names))+ 
geom_histogram(binwidth=20000, position=position_dodge())+ 
scale_y_continuous(limits=c(0,1000))+ 
scale_x_datetime(labels = date_format("%d-%m-%y"), 
       limits = as.POSIXct(c("2005-03-29","2005-04-02"))) 

它表現爲認爲數據爲3日30日,而不是31 Here's the graph image

感謝您可以給我的任何幫助:)

+0

時區快速瀏覽它與你做X,因爲規模的限制也由每1搬回。問題似乎在於'limits = as.POSIXct(c(「2005-03-29」,「2005-04-02」))' – MorganBall

+0

嘗試scale_x_date()並使用as.Date()作爲限制 –

回答

2

你需要指定as.POSIXct

limits = as.POSIXct(c("2005-03-29","2005-04-02"), tz="GMT")) 
+0

好吧,非常感謝 – user3819981