-1

我正在使用此代码生成绘图:

require(lattice)

allcol <- c("blue","chocolate4","cornflowerblue","chartreuse4","brown3","darkorange3","darkorchid3","red","deeppink4","lightsalmon3","yellow","mistyrose4","seagreen3","green","violet","palegreen4","grey","slateblue3","tomato2","darkgoldenrod2","chartreuse","orange","black","yellowgreen","slategray3","navy","firebrick1","darkslategray3","bisque3","goldenrod4","antiquewhite2","coral","blue4","cyan4","darkred","orangered","purple4","royalblue4","salmon")
names(logfile2d) <- c("Date","Client","Operations")
logfile2d <- read.table(file="/var/lib/nfs-estadoclientes/nfsclients-2d.log")
logfile=logfile2d
col=allcol[0:length(levels(logfile$Client))]

svg(filename="/var/lib/nfs-estadoclientes/nfsclients-2d.svg",width=14,height=7)

xyplot(Operations~Date,group=Client,data=logfile,jitter.x=T,jitter.y=T,
 aspect = 0.5, type = "l",
 par.settings=list(superpose.line=list(col=col,lwd=3)),
 xlab="Time", ylab="Operations", main="NFS Operations (last 2 days, only clients with >40 operations/sec)",
 key=list( text=list(levels(logfile$Client)), space='right',
           lines=list(col=col),columns=1,lwd=3,cex=0.75))

dev.off()

但是生成的绘图会打印很多 X 比例值,并且无法读取。X 刻度值是日期和小时,格式为:“mounth/day hour:minute”。似乎 R 没有将这些值作为数字来获取,而是尝试将它们全部写下来。

> dput(head(logfile$Date))
structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("01/09-06:43", 
"01/09-06:53", "01/09-07:03", "01/09-07:13", "01/09-07:23", "01/09-07:33", 
"01/09-07:43", "01/09-07:53", "01/09-08:03", "01/09-08:13", "01/09-08:23", 
"01/09-08:33", "01/09-08:43", "01/09-08:53", "01/09-09:03", "01/09-09:13", 
"01/09-09:23", "01/09-09:33", "01/09-09:43", "01/09-09:53", "01/09-10:03", 
"01/09-10:13", "01/09-10:23", "01/09-10:33", "01/09-10:43", "01/09-10:53", 
"01/09-11:03", "01/09-11:13", "01/09-11:23", "01/09-11:33", "01/09-11:43", 
"01/09-11:53", "01/09-12:03", "01/09-12:13", "01/09-12:23", "01/09-12:33", 
"01/09-12:43", "01/09-12:53", "01/09-13:03", "01/09-13:13", "01/09-13:23", 
"01/09-13:33", "01/09-13:43", "01/09-13:53", "01/09-14:03", "01/09-14:13", 
"01/09-14:24", "01/09-14:33", "01/09-14:43"), class = "factor")

也许最好的策略是省略中间值,但我不知道如何。我不知道如何让 R 意识到这些也不是数值。

生成图的屏幕截图

4

1 回答 1

1

您实际上需要strptime并且as.POSIXct因为您拥有日期和时间信息。这应该将您的Date列转换为 R 将正确绘制的实际日期/时间变量。运行这些后再次尝试您的绘图命令。

times <- as.POSIXct(strptime(levels(logfile$Date), format="%m/%d-%H:%M"))
logfile$Date <- times[logfile$Date]
于 2013-01-09T16:54:03.243 回答