0

I have data from a 3 axis accelerometer that I would like to create a graph of in R.

The data is currently in a CSV file that looks like this.

time,X_value,Y_value,Z_value
0.000,0.00000,0.00000,0.00000
0.014,-0.76674,3.02088,10.41717
0.076,-0.64344,3.08493,8.82323
0.132,-0.68893,3.01071,8.82862
0.193,0.48483,2.40438,9.73482
0.255,-0.71168,2.07637,8.94174
0.312,-0.32920,0.79188,10.77690
0.389,-0.54468,2.08236,9.77732
0.434,-1.53648,-0.00898,11.77887

I want to show the change in all three over time in one graph. Any suggestions on how I might do that?

Spacedman
  • 92,590
  • 12
  • 140
  • 224

1 Answers1

3

You'll want to read up on plotting in R. This is a fairly common analysis.

R: plot multiple lines in one graph

https://stats.stackexchange.com/questions/7439/how-to-change-data-between-wide-and-long-formats-in-r

You will want to melt the data frame and then plot it, grouped by your factors (x axis, y axis, z axis).

library(ggplot2)
library(reshape2)

t <- 1:10 
x <- rnorm(10)
y <- rnorm(10)
z <- rnorm(10)

df <- data.frame(t,x,y,z)

dfm <- melt(df, id.vars = "t")

ggplot(dfm, aes(x=t, y=value)) + geom_line(aes(color=variable))
Community
  • 1
  • 1
Lloyd Christmas
  • 1,016
  • 6
  • 15