Rukna's
Rukna's

Reputation: 71

Subscript and super script in R plot

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)

Upvotes: 1

Views: 607

Answers (1)

Dan
Dan

Reputation: 12084

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

plot(1:10, 1:10, xlab = expression(Acceleration~(ms^{-2})))

Upvotes: 0

Related Questions