我有下面的情节,我想在“11:20:33”
添加一条垂直线我试图使用:geom_vline(aes(xintercept =“11:20:33”))
但这似乎不起作用。有什么想法吗?
library(scales)
library(ggplot2)
time = as.POSIXct(c("2016-06-30 15:20:23 GMT","2016-06-30 15:20:25 GMT","2016-06-30 15:20:27 GMT","2016-06-30 15:20:29 GMT","2016-06-30 15:20:35 GMT"),tz = "GMT")
attr(time, "tzone") <- "America/New_York"
class(time)
value = c(10,NA,0, 5, 0)
category = c(0,0,0,0,0)
dat = data.frame(t = time, value = value, category = category)
dat
str(dat)
ggplot(dat, aes(x=t, y = value, group = 1 )) +
geom_point(aes (color = as.factor(category)) ) +geom_line() +
geom_vline(aes(xintercept = "11:20:33" )) +
scale_x_datetime(date_labels = "%H:%M:%S")+ theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 7))