Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的直方图和日期位置_R_Datetime_Ggplot2_Histogram - Fatal编程技术网

R中的直方图和日期位置

R中的直方图和日期位置,r,datetime,ggplot2,histogram,R,Datetime,Ggplot2,Histogram,当我绘制直方图时,它看起来不在正确的日期 我的数据是这样的 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

当我绘制直方图时,它看起来不在正确的日期

我的数据是这样的

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号


感谢您提供的任何帮助:)

您需要在as.POSIXct中指定时区

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

快速看一眼,它与您的x比例有关,因为每个限制也向后移动了1。问题似乎出在这行
limits=as.POSIXct(c(“2005-03-29”,“2005-04-02”)
尝试scale\u x\u date()并将as.date()用作限制