R 带有日期轴的绘图上的水平线

R 带有日期轴的绘图上的水平线,r,ggplot2,R,Ggplot2,我会在一个数据框中记录我的猫在何时以及多长时间内大便 df <- data.frame(name=c("fluffy", "misterCuddles", "senorEsnuggle")) df$start=as.POSIXlt(c("2014-04-03 23:57", "2014-04-03 23:31", "2014-04-04 00:02"), tz="EST") df$duration=c(123, 234, 345) 我可以这样画: ggplot(df, aes(x=nam

我会在一个数据框中记录我的猫在何时以及多长时间内大便

df <- data.frame(name=c("fluffy", "misterCuddles", "senorEsnuggle"))
df$start=as.POSIXlt(c("2014-04-03 23:57", "2014-04-03 23:31", "2014-04-04 00:02"), tz="EST")
df$duration=c(123, 234, 345)
我可以这样画:

ggplot(df, aes(x=name)) + 
    geom_linerange(aes(ymin=start, ymax=start + duration), size=10)

我如何在午夜放置一条水平线,将4月3日和4月4日分开

当我尝试这个:

ggplot(df, aes(x=name)) + 
    geom_linerange(aes(ymin=start, ymax=start + duration), size=10) +
    geom_hline(yintercept=as.POSIXlt("2014-04-04 00:00", tz="EST"))
我收到以下错误消息:

Error : Invalid intercept type: should be a numeric vector, a function, or a name of a function

它与数值版的
yintercept

ggplot(df, aes(x = name)) +
  geom_linerange(aes(ymin = start, ymax = start + duration), size = 10) +
  geom_hline(yintercept = as.numeric(as.POSIXlt("2014-04-04 00:00", tz = "EST")))

PS:我尝试了'start'和'code>yintercept的
as.POSIXct
版本,但没有成功

ggplot(df, aes(x = name)) +
  geom_linerange(aes(ymin = start, ymax = start + duration), size = 10) +
  geom_hline(yintercept = as.numeric(as.POSIXlt("2014-04-04 00:00", tz = "EST")))