r - Geom_vline time's value -
i'm trying add vertical line specify x limit value. data :
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 time specify time when measured variable, no date. problem geom_vline, see in few posts, require date. since, i've no need have date's information. how can use geom_vline without date ?
as follow code i'm trying use, not work simple date. there other alternative of as.posixct ? code work when hour has form 2017-08-15 07:32:00 cest , posixct("2017-08-15 00:53:00"). want hour time.
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")
you code treats 'hour' discrete variable , not time wouldn't rather pick arbitrary date , work dates?:
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") alternatively if must have plot time not scale:
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") ggplot(meltk1, aes(x=hour, y = value, group = variable, colour = variable)) + geom_line(size=1) + geom_vline(xintercept = 3, color = "black", linetype = "dashed")
Comments
Post a Comment