Question

I'm trying to create a ylab for my plot in m/s^2.

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)

The problem is after the ^ symbol ] gets superscripted.

enter image description here

with my code I get this error,

> 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}"]"
                                                                                                     ^
Was it helpful?

Solution

Try: 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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top