问题
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.

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}"]"
^
回答1:
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)

来源:https://stackoverflow.com/questions/22487229/cant-write-the-subscript-in-expression-in-r