r - ggplot2 axis as time with 1 hour error

问题描述:

This question already has an answer here:

Time series plot gets offset by 2 hours if scale_x_datetime is used

2 answers

网友答案:

You need to specify the time zone in scale_x_datetime.

The function date_format() is by default set to "UTC". Therefore, your labels are converted to UTC. To use the time zone e.g. I used "Europe/London" (to get your desired output), you can do the following in your ggplot code: labels = date_format("%H:%M", tz = "Europe/London")

But firstly in order to run your code I also had to define what you specified in your code as fmt_decimals So I used this function given by @joran:

fmt_dcimals <- function(decimals=0){
# return a function responpsible for formatting the
# axis labels with a given number of decimals
function(x) as.character(round(x,decimals))
}