1

I want to visualize data from an acceleration sensor. I have a data frame with four columns: time (PosiXlt), AccX, AccY, AccZ (all as numeric) and around 33 million rows. Here is the head of my file:

    "time"              "AccX.in.G" "AccY.in.G" "AccZ.in.G"
2015-06-24 04:00:00.092 -0.789  0.516   -0.374
2015-06-24 04:00:00.102 -0.782  0.52    -0.374
2015-06-24 04:00:00.112 -0.786  0.52    -0.371
2015-06-24 04:00:00.121 -0.786  0.516   -0.374
2015-06-24 04:00:00.131 -0.782  0.52    -0.371
2015-06-24 04:00:00.141 -0.782  0.52    -0.371

I want to have a plot with the time as x-axis and the other three values as lines. I tried plotting with ggplot:

library(ggplot2)
library(reshape2)
Molten <- melt(MSR46, id.vars = "time")
ggplot(Molten, aes(x=time, y= value, group = variable)) + geom_line()

The error I'm getting is

Aesthetics must either be length one, or the same length as the dataProblems:time

I checked the length of all variables and they are all the same.

I therefore don't know what I'm doing wrong. I'm sure its simple but I just don't get it.

Can someone please help me? Thanks

here the

 dput(head(MSR46,10)) 
of my file:
"","time","AccX.in.G","AccY.in.G","AccZ.in.G"
"2",2015-06-24 04:00:00.092,-0.789,0.516,-0.374
"3",2015-06-24 04:00:00.102,-0.782,0.52,-0.374
"4",2015-06-24 04:00:00.112,-0.786,0.52,-0.371
"5",2015-06-24 04:00:00.121,-0.786,0.516,-0.374
"6",2015-06-24 04:00:00.131,-0.782,0.52,-0.371
"7",2015-06-24 04:00:00.141,-0.782,0.52,-0.371
"8",2015-06-24 04:00:00.151,-0.782,0.52,-0.378
"9",2015-06-24 04:00:00.161,-0.786,0.52,-0.374
"10",2015-06-24 04:00:00.171,-0.782,0.52,-0.374
"11",2015-06-24 04:00:00.181,-0.782,0.52,-0.371
Pedde
  • 11
  • 3
  • Including the output of a `dput()` is always better to give some ample data, e.g.: `dput(head(MSR46, 10))` – Jaap Sep 07 '15 at 12:27
  • 1
    Did you try `color = variable` instead of `group = variable`? – Jaap Sep 07 '15 at 12:27
  • And if what @Jaap suggests doesn't work, try both, i.e., `color=variable, group=variable`. – ulfelder Sep 07 '15 at 12:35
  • I tried bot, color=variable' and "color=varialbe, group=variable". Sill doesn't work – Pedde Sep 07 '15 at 12:41
  • 1
    Does the problem persist in an empty environment/new session? Because with your sample data/code I could not replicate your error. – Heroka Sep 07 '15 at 12:43
  • It's an empty environment and I also tried a new session – Pedde Sep 07 '15 at 12:47
  • 2
    I also couldn't replicate the problem with the data provided. Most likely you have NA's or NULL's somewhere in your data. Otherwise try to provide the dput() of minimal amount of data that replicates the error – Maksim Gayduk Sep 07 '15 at 13:01
  • NOTE: (to answerers): this is _most likely_ Coursera homework. – hrbrmstr Sep 07 '15 at 13:38
  • the file should not contain NA'S or NULL's since I deleted them. I added the dput() of the file in my question and even with these 10 rows I get the same error. Can u replicate it now? – Pedde Sep 07 '15 at 14:12
  • 1
    That's not the output of a `dput()`. You only have to copy the output. It looks like this: `structure(...etc...)` – Jaap Sep 07 '15 at 14:22
  • Look at Molten. I think something is going wrong with reshape2 and the class of PosiXlt. – Heroka Sep 07 '15 at 16:07
  • 1
    I don't know why, but reshape doesn't work well with PosiXlt. Does it work if you convert your time variable to POSIXct before melting? – Heroka Sep 07 '15 at 16:13
  • @Heroka was right: converting the time to PosiXlt solved the problem! Thanks a lot! – Pedde Sep 08 '15 at 11:49
  • @Pedde hooray! For future questions, please provide the appropriate data that's asked for. (`dput()`). It would lead to a faster solution.... – Heroka Sep 08 '15 at 12:10
  • I would have liked to, but the dput() output was just too large!? – Pedde Sep 08 '15 at 12:48

0 Answers0