R 几何线时间';s值
我正在尝试添加指定X限制值的垂直线。我的数据:R 几何线时间';s值,r,R,我正在尝试添加指定X限制值的垂直线。我的数据: meltk1=structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "number", class = "factor"), value = c(0L, 85L, 65L, 35L, 28L, 124L), Hour = c("00:23:00", "00:29:00", "00:53:00", "04:51:00", "
meltk1=structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "number", class = "factor"),
value = c(0L, 85L, 65L, 35L, 28L, 124L), Hour = c("00:23:00",
"00:29:00", "00:53:00", "04:51:00", "05:08:00", "05:23:00"
)), .Names = c("variable", "value", "Hour"), row.names = c(168L,
169L, 170L, 1L, 2L, 3L), class = "data.frame")
Hour
是时间指定我测量变量的时间,没有日期。正如我在几篇文章中看到的,geom_vline
的问题是,它需要一个日期。因为,我不需要日期信息。我如何使用没有日期的geom_vline
正如下面的代码,我试图使用,但不工作的简单日期。作为.POSIXct,是否还有其他替代方法?当Hour
具有此表单时,此代码有效2017-08-15 07:32:00 CEST
和POSIXct(“2017-08-15 00:53:00”)
。但我只想要小时
作为时间
ggplot(meltk1, aes(x=Hour, y = value, group = variable, colour = variable)) +
geom_line(size=1) +
geom_vline(aes(xintercept = as.numeric(as.POSIXct("00:53:00"))), color = "black", linetype = "dashed")
您的代码将“小时”视为离散变量,而不是时间。您是否愿意选择任意日期并处理日期
library(ggplot2)
meltk1=structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L),
.Label = "number", class = "factor"),
value = c(0L, 85L, 65L, 35L, 28L, 124L), Hour = c("00:23:00",
"00:29:00", "00:53:00", "04:51:00", "05:08:00", "05:23:00"
)), .Names = c("variable", "value", "Hour"), row.names = c(168L,
169L,
170L, 1L, 2L, 3L), class = "data.frame")
meltk1$Hour <- as.POSIXct(paste("2017-01-01", meltk1$Hour, "CEST"))
ggplot(meltk1, aes(x=Hour, y = value, group = variable, colour =
variable)) +
geom_line(size=1) +
geom_vline(xintercept = as.numeric(as.POSIXct("2017-01-01 00:53:00 CEST")), color = "black", linetype = "dashed")
您的代码将“小时”视为离散变量,而不是时间。您是否愿意选择任意日期并处理日期
library(ggplot2)
meltk1=structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L),
.Label = "number", class = "factor"),
value = c(0L, 85L, 65L, 35L, 28L, 124L), Hour = c("00:23:00",
"00:29:00", "00:53:00", "04:51:00", "05:08:00", "05:23:00"
)), .Names = c("variable", "value", "Hour"), row.names = c(168L,
169L,
170L, 1L, 2L, 3L), class = "data.frame")
meltk1$Hour <- as.POSIXct(paste("2017-01-01", meltk1$Hour, "CEST"))
ggplot(meltk1, aes(x=Hour, y = value, group = variable, colour =
variable)) +
geom_line(size=1) +
geom_vline(xintercept = as.numeric(as.POSIXct("2017-01-01 00:53:00 CEST")), color = "black", linetype = "dashed")