0

Have data with POXIS date and Events Y:/R/Rtest.txt

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

So all the data are for the same day. I need to plot a X-Y grap where X-axis is Mins"Sec and Y axis is the values in Num and when mouse curser goes over the dots, it needs show "Event1" etc strings.

How to use gvisAnnotatedTimeLine() ? to draw the plot. Can you provide examples. I can change the date/time format if needed.

Program tried are

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)
4

1 回答 1

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)

在此处输入图像描述

于 2013-01-25T09:38:54.827 回答