user3819981 user3819981 - 29 days ago 15
R Question

Histogram and date position in R

My histogram doesn't look like it's on the correct date when I plot it.

My data looks like this

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


My Code looks like

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")))


It's appearing as thought the data is for the 30th of the 3rd and not the 31st
Here's the graph image

Thanks for any help you can give me :)

Answer

you need to specify the time zone in as.POSIXct

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