Place a fixed caption in an interactive 3D plot using the rgl, R package

I am trying to add a fixed caption to an interactive 3D plot using the rgl package from R, but so far I have not been able to do this. I would also like to have one main title and subtitle under the main title.

Here is a sample code,

library(rgl) data<-read.table(text=" XYZ 1 147.0883 -18.69122 -13.90000 2 147.0894 -18.69455 -10.97250 3 147.0883 -18.69122 -17.45000 4 147.0883 -18.69122 -15.44000 5 147.0883 -18.69122 -13.45000 6 147.0909 -18.69922 -12.25000 7 147.0883 -18.69122 -17.30000 8 147.0883 -18.69122 -16.40000 9 147.0883 -18.69122 -14.30000 10 147.0883 -18.69122 -18.50000 11 147.0883 -18.69122 -15.67606 12 147.0883 -18.69122 -17.25780 13 147.0883 -18.69122 -3.64000 14 147.1164 -18.68133 -22.13000 15 147.0883 -18.69122 -18.54778 16 147.0883 -18.69122 -15.50000 17 147.1185 -18.68691 -14.55500 18 147.0883 -18.69122 -18.12500 19 147.0901 -18.69670 -14.39767",header=T) data a<-as.matrix(data) # call the plug-in bandwidth estimator H.pi<-Hpi(a,binned=TRUE)*3 ## a is a matrix of x,y,z points # calculate the kernel densities fhat<-kde(a,H=H.pi) # produce a 3D plot open3d() title<-"Individual 1 (male)" # main title title2<-"Site A" # subtitle plot(fhat,cont=c(50,95),colors=c("green","red"),drawpoints=TRUE, xlab="",ylab="", zlab="",size=1.5,ptcol="black", axes=F,box=T,aspect=c(1,1,0.5),zlim=c(-40,0)) axes3d(c("x--","y--","z-+"),cex=0.8) mtext3d("Longitude",edge="x--",line=3,las=2,cex=1.1) mtext3d("Latitude",edge="y--",line=3,las=2,cex=1.1) mtext3d("Depth (m)",edge="z-+",line=3,las=2,cex=1.1) title3d(main=title,sub=title2,line=4) 

I did not find a good way to have a fixed title (and subtitles) so that when exporting my plot as a 3D movie, the main title does not rotate with the chart ...

 movie3d(spin3d(axis=c(0,0,1), rpm=4),dir="~/Dropbox/R/Sample plots", duration=15, fps=10, movie="Plot 1") 

If you have a good / easy way to place the main heading in a fixed place (and maybe add an additional heading under), that would be great. Thanks in advance,

+7
r interactive plot title rgl
source share
4 answers

This is currently not possible to do in rgl.

+2
source share

Adding a title to the RGL chart is now possible thanks to an update dated last year.

The idea is to use the new bgplot3d function, which is brought to the background of the RGL window, as if it were a normal plot.

For example:

 # A minimal plot3d example library(rgl) a = matrix(runif(3000), ncol=3) plot3d(a, col = rainbow(100)[cut(a[,1], breaks = seq(0,1,le=101), include.lowest = T)]) bgplot3d({ plot.new() title(main = 'This is the main title', line = 3) mtext(side = 1, 'This is a subtitle', line = 4) # use here any other way you fancy to write your title }) 

What gives:

RGL name with plot3d and bgplot3d

There is one pretty important caveat, though, as stated on the help page for bgplot3d :

Since background pictures are drawn as bitmap images, they do not change very elegantly. It’s best to draw a window first and then draw a background at this size.

+12
source share

There is no play of your kde script (the library is not included) ... in any case, have you considered using: adding after movie:

 text3d(x=0.08, y=0.97, z=0.03, title.main ,col="Blue") 

where: x, y, z are the locations in your graph. I use this with scatter3d (using rgl as well).

+1
source share

Like the test proposal, you can add a legend that remains motionless and use it as a name. Example below from Adding Legends to rgl 3D Graphics

 legend3d("topright", legend = paste('Type', c('A', 'B', 'C')), pch = 16, col = rainbow(3), cex=1, inset=c(0.02)) 
0
source share

All Articles