我有一個巨大的數據與日期,客戶端和它的NFS使用收集。我使用格子R包進行繪圖,as adviced on superuser。另外,Stackoverflow幫助我在converting the date string to an actual date object。現在個性化X軸值顯示在R使用格
,我的代碼是這樣的:
require(lattice)
logfile <- read.table(file="nfsclients-2d.log")
names(logfile) <- c("Date","Client","Operations")
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")
col=allcol[0:length(levels(logfile$Client))]
svg(filename="/tmp/nfsclients-2d.svg",width=14,height=7)
times <- as.POSIXct(strptime(levels(logfile$Date), format="%m/%d-%H:%M"))
logfile$Date <- times[logfile$Date]
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軸值不是非常有用這裏: 「tue」「tue」「wed」「結婚」。它似乎只將第一個有意義的值作爲標籤。一些更多的標籤(也許6或7)也會更有用。
當繪製2周時,情況更糟。 X軸上只顯示2個值:「2012」「2013」。甚至沒有重複,只有2個值!
The data I'm plotting。
這不是一個回答你的問題,而是一個仍然在R內的替代方法可能是ggplot2(您需要先從CRAN安裝它),它可以提供類似於格的功能,但基於一致的「圖形語法」。出於您的目的,您可能更喜歡默認設置。你的基本命令就像ggplot(logfile,aes(x = Date,y = Operations,color = Client))+ geom_line()。您可以添加scale_color_manual()命令以使用您喜歡的顏色。 –