How to plot a greek letter on a 3D plot label with hist3D()?

3.1k views Asked by At

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)

3

There are 3 answers

0
Sven Hohenstein On

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

1
agstudy On

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)
0
Vladimir S. On

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