我正在绘制一些事件发生的一天中的小时。但是,我正在使用Shiny,我想事先设置图形的ylim。这是我到目前为止所尝试的内容
#my data
structure(list(Data = structure(c(15971, 15972, 15973, 15974,
15975, 15978, 15971, 15972, 15973, 15974, 15975, 15978), class = "Date"),
Nome = c("dummyName", "dummyName", "dummyName", "dummyName",
"dummyName", "dummyName", "dummyName", "dummyName", "dummyName",
"dummyName", "dummyName", "dummyName"), hora = structure(c(1382013987,
1382014626, 1382015134, 1382014112, 1382013981, 1382013761,
1382044587, 1382044676, 1382044398, 1382044961, 1382047646,
1382044149), class = c("POSIXct", "POSIXt"), tzone = ""),
tipo = c("entrada", "entrada", "entrada", "entrada", "entrada",
"entrada", "saida", "saida", "saida", "saida", "saida", "saida"
), minHora = structure(c(1378090800, 1378090800, 1378090800,
1378090800, 1378090800, 1378090800, 1378090800, 1378090800,
1378090800, 1378090800, 1378090800, 1378090800), class = c("POSIXct",
"POSIXt")), maxhora = structure(c(1378177140, 1378177140,
1378177140, 1378177140, 1378177140, 1378177140, 1378177140,
1378177140, 1378177140, 1378177140, 1378177140, 1378177140
), class = c("POSIXct", "POSIXt"))), .Names = c("Data", "Nome",
"hora", "tipo", "minHora", "maxhora"), class = c("data.table",
"data.frame"), row.names = c(NA, -12L), .internal.selfref = <pointer: 0x003524a0>)
# code to render my plot
p5 <- ggplot(myDf, aes(Data, hora)) +
geom_line(aes(group=tipo))
p5
但是,我希望图形在某个值(例如00:00:00或06:00:00)开始ylim并以另一个(可能是固定的)值结束。我尝试使用scale_y_datetime,如下所示:
myDf$minHora <- as.POSIXct(paste(min(myDf$Data), "06:00:00"), format="%Y-%m-%d %H:%M:%S")
myDf$maxhora <- as.POSIXct(paste(min(myDf$Data), "23:59:00"), format="%Y-%m-%d %H:%M:%S")
p5 + scale_y_datetime(limits=c(min(minHora) , max(maxhora) ))
这几乎是我想要的。唯一的问题是小时旁边的月份(10月)的名称。我真的不喜欢下个月的月份。
ps。:我在闪亮的时候使用ggplot。它可能没有任何区别。