4

I do a 3d plot with the rgl package and I want to use a log transformed z axes. What I do is:

# Dummy data. x <- seq(1, 2, length = 10); y <- seq(1, 3, length = 10) z <- outer(x, y, function(x, y) x + exp(y)); z <- log(z) # Plot. rgl::persp3d(x, y, z, col= "white") rgl::surface3d(x, y, z, front = "lines") 

Log Plot

The 3d object looks as I expect. But I want the z labels not to say the log values, instead I want it to show the raw values, i.e. where the 3 is there should be a 20 (since exp(3) is approx. 20). So I am looking for some equivalent to ggplot2::scale_y_continuous(trans= "log10") as discussed here. How to do this with the rgl package?

1 Answer 1

2

One way is to tell persp3d() to skip the axes, then use calls like axes3d(), box3d(), axis3d() or bbox3d()to draw them where you want them. For example,

library(rgl) x <- seq(1, 2, length = 10); y <- seq(1, 3, length = 10) z <- outer(x, y, function(x, y) x + exp(y)); z <- log10(z) # Plot. open3d() persp3d(x, y, z, col= "white", polygon_offset = 1) surface3d(x, y, z, front = "lines") zticks <- pretty(z) zlabels <- signif(10^zticks, 2) axes3d(zat = zticks, zlab = zlabels) 

The help page for the latest version (1.3.14) shows a slightly simpler way using axes3d().

Sign up to request clarification or add additional context in comments.

2 Comments

Looks nice but for some reason the labels appear on another box side than the axes name. I would like the labels to be at the same place as the axes name but have no idea how to set this
You can use axes3d(zat = zticks, zlab = zlabels) for a better solution. I forgot that axes3d() accepts most of the arguments of bbox3d(). Don't say axes=FALSE in the persp3d() call if you want to keep the box.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.