1

How to write the following expression in R plot function:

$$Acceleration (ms^{-2})$$

I have tried to use expression(), but it does not work for text and equations together.

[Updated]

Usually, it does not work in R Surf 3D plot. Here is an example:

pm <- par("mflow")
pmar <- par("mar")
par(mar=c(2,2,2,2))
par(mflow=c(1,1))
velocity <- seq(0,35,length.out=50)
acceleration <- seq(-2,3,length.out=50)
M <- mesh(velocity,acceleration)
alpha <- M$x
beta <- M$y
x<- 1* alpha
y <- 1*beta
z <- (1300*alpha*beta+0.5*1.20*1.97*0.33*alpha*alpha*alpha + 
     1300*9.8*0.018*alpha)/(1000*.9*.97)

surf3D(x,y,z,colkey=FALSE,colvar=z,drap=TRUE, shade = 0.0, 
  lighting = TRUE,bty="b2",theta=40, sub="subtitle",
  xlab = expression(Velocity~(ms^{-1})), 
  ylab = expression(Acceleration~(ms^{-2})), 
  zlab = expression(Energy consumption~(mAhs^{-1})),
  xlim = c(0, 35), ylim=c(-2, 3), ticktype="detailed", 
  facets=FALSE,phi=10,cex.lab=1.5,font.lab=2,lwd=1.5)
kangaroo_cliff
  • 6,067
  • 3
  • 29
  • 42
Rukna's
  • 71
  • 1
  • 7
  • More generally, this answer describes subscripts and superscripts. https://stackoverflow.com/questions/10156417/subscripts-in-plots-in-r – Tom Kelly Oct 29 '20 at 08:06

1 Answers1

0

Try expression(Acceleration~(ms^{-2})) like this:

plot(1:10, 1:10, xlab = expression(Acceleration~(ms^{-2})))
Dan
  • 11,370
  • 4
  • 43
  • 68
  • Do you know how to move position of xlab and ylab? My labels are truncated by border. – Rukna's May 08 '17 at 18:42
  • This sort of thing has been addressed many times (e.g., http://stackoverflow.com/questions/8100765/y-axis-label-falling-outside-graphics-window). Search Stackoverflow and if you can't find the exact solution post a question with a reproducible example of the problem. – Dan May 09 '17 at 11:24
  • I have updaed my post and provided an example. – Rukna's May 09 '17 at 14:17