所以我创建了一个时间序列事件。我想将我的NS数据绘制在y轴上。不幸的是,它不起作用,我不知道为什么。我想将其绘制为条形图。 x值输入应该是我新创建的DateTime。有备注吗?
library(ggplot2)
library(scales)
Versuch3 <- data.frame(date = c("1.1.2015", "2.1.2015", "3.1.2015"),
time = c("06:12:03", "08:23:45", "15:40:32"),
NS = c("0.3", "0.4", "0.6"),
status = c("0", "1", "0"))
Versuch3$DateTime <- paste(Versuch3$date,Versuch3$time,sep =" ")
Versuch3$DateTime <- as.POSIXct(strptime(Versuch3$DateTime, "%d.%m.%Y %H:%M:%S"))
Versuch3$NS <- as.integer(Versuch3$NS)
dtLimits <- c(as.POSIXct("2014-12-01 00:00:00"), as.POSIXct("2015-07-01 00:00:00"))
#plot
ggplot(data = Versuch3, aes(x=DateTime, y=NS)) +
geom_bar(stat="identity", aes(fill=status), width = 3) +
scale_x_datetime(date_breaks = "1 month",
labels = date_format("%d.%m.%Y %H:%M:%S"),
limits = dtLimits) +
theme(axis.text.x = element_text(angle = 90, vjust = .5))