不能在R中的表达式中写下标

时间:2014-03-18 17:53:31

标签: r label expression

我试图以m / s ^ 2为我的情节创建ylab

plot(mydata[,1], mydata[,3], type  = "l", xlab="Time [s]", ylab=expression("Acceleration [m/s"^{2}"]"), 
     main="Example of signal of horizontal acceleration", cex.main = 0.9)

问题出在^符号]上标后。

enter image description here

使用我的代码我收到此错误,

> source('~/Dropbox/WORK/ISRProject/R_projects/plots_report.R')
Error in source("~/Dropbox/WORK/ISRProject/R_projects/plots_report.R") : 
  ~/Dropbox/WORK/ISRProject/R_projects/plots_report.R:26:99: unexpected ']'
25: 
26: plot(mydata[,1], mydata[,3], type  = "l", xlab="Time [s]", ylab=expression("Acceleration [m/s"^{2}"]"
                                                                                                     ^

1 个答案:

答案 0 :(得分:1)

尝试:ylab=expression(paste("Acceleration [ ",m/s^{2}," ]"))

par(mar=c(4,5,4,4))
x <- seq(1,10,.01)
plot(x, sin(pi/2*x), type  = "l", xlab="Time [s]", 
     ylab=expression(paste("Acceleration [ ",m/s^{2}," ]")), 
     main="Example of signal of horizontal acceleration", cex.main = 0.9)