4

I am plotting a 3D histogram using hist3D(), and want to change xlab so that it includes a Greek letter with a subscript.

I used

xlab=expression(theta[1]). 

It doesn't work, and I just get the string "theta[1]" in the label. It works fine, on the other hand, for just the regular plot command.

So how can I introduce subscripted Greek letters to hist3D() plots?

(hist3D() is in the plot3D library)

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
kloop
  • 4,537
  • 13
  • 42
  • 66
  • 2
    you should add a reproducible example and mention which package are you using. – agstudy Dec 13 '13 at 10:03
  • 2
    The function `hist3D` calls the function `persp`. From `?persp`, concerning `xlab`: `These must be character strings; expressions are not accepted.` – Sven Hohenstein Dec 13 '13 at 10:28

3 Answers3

3

The hist3Dfunction does not accept expressions for axis labels. One workaround is to use the Unicode character for theta, θ.

# example data
library(plot3D)
x <- seq(-pi, pi, by = 0.2)
y <- seq(-pi, pi, by = 0.3)
grid <- mesh(x, y)
z <- with(grid, cos(x) * sin(y))

hist3D(z = z, x = x, y = y, border = "black", xlab = "θ1")

This displays a theta symbol but no subscript 1.

enter image description here

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
3

Another workaround is to use text3D function from the same plot3D package. It accepts the math expressions as labels so we can write as usual expression(theta[1]). The only minor issue in this workaround is to find the suitable coordinates of our label

# example data
library(plot3D)
x <- seq(-pi, pi, by = 0.2)
y <- seq(-pi, pi, by = 0.3)
grid <- mesh(x, y)
z <- with(grid, cos(x) * sin(y))

hist3D(z = z, x = x, y = y, border = "black", ticktype = "detailed", xlab = "", ylab="y", zlab="z")
text3D(2, -5, 0, labels = expression(theta[1]), add = TRUE, adj = 1)

I have found that 2,-5,0 are quite good for this example. The label is not rotated one as in case of the regular labels. enter image description here

Vladimir S.
  • 511
  • 4
  • 13
0

A workaround is to use scatterplot3d:

enter image description here

z <- seq(-10, 10, 0.01)
x <- cos(z)+1
y <- sin(z)+1
scatterplot3d(volcano, highlight.3d=TRUE, col.axis="blue",
                            col.grid="gray", main="scatterplot-greeks", pch=21,
                            xlab=expression(theta[1]),
                            ylab=expression(beta[2]),
                            zlab=expression(alpha[3]),cex.lab=1.5)
agstudy
  • 119,832
  • 17
  • 199
  • 261