我有来自3轴加速度计的数据,我想在R中创建图表。
数据目前位于CSV文件中,如下所示。
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
我想在一张图中显示所有三种变化。关于我如何做到这一点的任何建议?
答案 0 :(得分:3)
您想要阅读R中的绘图。这是一个相当常见的分析。
R: plot multiple lines in one graph
https://stats.stackexchange.com/questions/7439/how-to-change-data-between-wide-and-long-formats-in-r
您需要melt
数据框然后绘制它,按您的因子(x轴,y轴,z轴)分组。
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))