2013-01-25 39 views
0

具有POXIS日期和數據活動 Y:/R/Rtest.txt使用gvisAnnotatedTimeLine繪製X軸在小時的術語:分:秒圖表

Date   ?NUM ?Label 
201301241035 ?1  ?Event1 
201301241036 ?2  ?Event2 
201301241037 ?3  ?Event3 

因此,所有的數據都是相同的天。我需要繪製一個XY圖形,其中X軸爲Mins「Sec和Y軸爲Num中的值,當鼠標光標移過這些圓點時,它需要顯示」Event1「等字符串。 )?繪製曲線。 你能提供的例子。如果需要,我可以更改日期/時間格式。

程序試圖在

data3=read.table(file="Y:/R/Rtest.txt", header=TRUE, sep="?") 

line3=gvisAnnotatedTimeLine(data3, datevar="Date")) 
    Error: unexpected ')' in "line3=gvisAnnotatedTimeLine(data3, datevar="Date"))" 

    line3=gvisAnnotatedTimeLine(data3, datevar="Date") 
    Error in as.Date.numeric(x) : 'origin' must be supplied 
    class(data3$Date) = c('POSIXt', 'POSIXct') 
    line3=gvisAnnotatedTimeLine(data3, datevar="Date") 
    plot(line3) 
+0

基本查找示例代碼,其中X軸可以在HH:mm:ss –

回答

0

這應該工作

## read your data with header, you replace text ='..' with file=fileName 
dat <- read.table(text = 'Date   ?NUM ?Label 
201301241035 ?1  ?Event1 
201301241036 ?2  ?Event2 
201301241037 ?3  ?Event3',header=T) 
## rename the columns 
colnames(dat) <- c('Date','Value','Label') 
## format columns and remove special character 
dat$Date <- as.POSIXct(strptime(dat$Date,'%Y%m%d%H%M')) 
dat$Value <- as.numeric(gsub('[?]','',dat$Value)) 
dat$Label <- gsub('[?]','',dat$Label) 
## build the plot, here I use minimum options, 
## to show the plot as below 
A1 <- gvisAnnotatedTimeLine(dat, 
          datevar ="Date", 
          numvar ="Value", 
          annotationvar="Label", 
          options=list(displayAnnotations=TRUE, 
             width=600, height=350)) 
plot(A1) 

enter image description here

+0

我得到以下錯誤,並且繪圖將爲空白。 A1 < - gvisAnnotatedTimeLine(dat,datevar =「Date」,numvar =「Value」,annotationvar =「Label」,options = list(displayAnnotations = TRUE,width = 600,height = 350)) 警告:數據看起來更多比同一日期的一個條目。 你有沒有考慮過使用idvar變量? –

+0

我的GoogleVis版本也是0.3.3和R 1.15.2。和你的例子一樣。 –

+0

@harshanagaraju錯誤提示您刪除重複的日期,嘗試類似'dat < - dat [!duplicate(dat $ Date),]' – agstudy

相關問題