0

enter image description hereI am trying to plot a line graph in R of Roll against time with RSudio. The X and Y values are correct but the entire graph is Black

mru <- read.csv("E:/r-train/mru.txt", header = TRUE, sep = ",")
attach(mru)
plot( time, p1)

Time,r1,p1,h1,r2,p2,h2,r3,p3,h3
14:07:32,-0.08,0.41,0,-0.45,0.8145,1.4436,0.46,-0.06,0
14:07:33,-0.07,0.41,0,-0.459,0.8001,1.4436,0.46,-0.06,0

I also tried to format the time mru <- read.csv("E/r-train/mru.txt", header = TRUE, sep = ",", format='%H:%M:%S') and got the same result.

Also tried this: and it did not work

mru <- read.csv("E:/r-train/mru.txt", header = TRUE, sep = ",", as.is = TRUE)
mru[,1] <- as.POSIXct(strptime(mru[,1],"%H:%M:%S"))
plot(Time, h1)

Because it does this:

 $ Time: POSIXct, format: "2015-03-26 14:07:00" "2015-03-26 14:07:00" "2015-03-26 14:07:00" "2015-03-26 14:07:00" ...
 $ r1  : chr  "-0.08" "-0.07" "-0.07" "-0.07" ...
risail
  • 509
  • 5
  • 14
  • 37
  • 1
    Why don't you supply what the first few lines of your dataframe look like. There's not much anyone can do to help you just knowing the name of your file – C_Z_ Mar 25 '15 at 19:46
  • 2
    Please include a [minimum reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), otherwise it's nearly impossible for us to help. – Alex A. Mar 25 '15 at 19:48
  • In the example data you've included, `Time` is capitalized, whereas it isn't in your data. Also you should check the variable type of `time`. Try `plot(p1 ~ time, data=mru)` rather than attaching it. – Alex A. Mar 25 '15 at 19:50
  • The result is the same `Time` or `time` and `plot(p1 ~ time, data=mru)` nets the same result – risail Mar 25 '15 at 19:52
  • 2
    The `read.csv` function is going to turn all the "Time" column into a factor variable. Look at `str(mru)` and learn NOT to use `attach()`. There is no "format"-parameter to `read.csv()` so that second call should have prompted an error message. – IRTFM Mar 25 '15 at 20:13
  • @BondedDust They are all factors after removing `attach()` how do I get them to `ints`? – risail Mar 25 '15 at 20:17
  • You want to convert 'Time' to either a time or a data-time class and the others to "numeric". Converting factor to numeric (properly) is discussed in the R-FAQ. Converting to `POSIXct` is done with `strptime` and I think there is an `as.POSIXct.factor` method. – IRTFM Mar 25 '15 at 20:28

0 Answers0