我需要一个想法,如何将从0到24小时的情节分成12到24和0到12.结果我希望在情节中间有半夜。
# sample data
date <- strptime(paste0("2014-",c(rep(sample(90:300, 100),4))), "%Y-%j")
h <- c(rep(paste(sprintf("%02d",as.numeric(sample(c(0:7,22:23))), 10),
sample(10:59, 50),sep=":"),8))
# plot data
hour <- strptime(paste(date, h), "%Y-%m-%d %H:%M")
time <- difftime(hour, date , units="hours")
startMonth <- as.POSIXct(as.Date("2014-01-01", format="%Y-%m-%d"))
endMonth <- as.POSIXct(as.Date("2014-12-31", format="%Y-%m-%d"))
plot(x=date, y=time, xlim=c(startMonth, endMonth), ylim=c(24, 0) )
目前结果如下: http://i.stack.imgur.com/5rqu1.png
我的目标是午夜线位于情节的中间。有线索吗?
答案 0 :(得分:1)
plot(x=date, y=time - 24 * (time > 12),
xlim=c(startMonth, endMonth), ylim=c(12,-12),
yaxt = "none",
ylab = "time")
breaks <- pretty(range(12, -12))
axis(2, at = breaks,
label = breaks + 24 * (breaks < 0 ))