2013-07-21 10 views
7

我想用R的rgl包添加一個固定標題到交互式3d圖,但到目前爲止我還沒有做到。我還希望在主標題下有一個主標題和一個小標題。使用rgl包在交互式三維圖中放置一個固定標題R

這裏是一個示例代碼,

library(rgl) 

data<-read.table(text="   X   Y   Z 
       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) 

我還沒有發現具有固定的標題(和字幕),所以,當我在我的情節導出爲3D電影,主標題是一個很好的方式不與劇情旋轉...

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

如果你把主標題在固定位置(也可能加入下一個次要標題)的良好/簡單的方法,這將是巨大的。在此先感謝,

+0

我想'rgl'是不可能的。使用其他軟件製作影片後,您可以考慮添加標題。 –

回答

2

這不能在rgl目前完成。

+0

當情節正在移動時,是否有辦法在背景的固定位置至少放置主標題? – user1626688

+2

否 - ?rgl.texts表示文本位於3D空間中,面向用戶。 rgl圖形設備不使用標準R繪圖系統,所以'text'不起作用,'title'不起作用等。我認爲它只需要在C++級別上使用ftgl實現2d靜態文本的一些工作rgl用於其文本的庫。 – Spacedman

+5

請參閱[這裏](http://stackoverflow.com/a/33425187/3001626) –

1

要重現你的腳本KDE丟失(不包括庫)......在任何情況下 你有沒有考慮使用:看完電影后增加:

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

其中:x,y,z是位置在你的圖形中。我已經與scatter3d一起使用(也使用rgl)。

0

與關於測試的建議類似,您可以添加一個固定的圖例並將其用作標題。請參閱從Adding a legend to an rgl 3d plot

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

把標題在RGL情節下面的例子是現在可以,由於更新的歷史可以追溯到去年。

這個想法是使用輸出到RGL窗口背景的新函數bgplot3d,就好像它是一個正常的圖。

例如:

# 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 
}) 

其中給出:

                                                                                                RGL title with plot3d and bgplot3d

有一個非常重要的警告雖然說作爲幫助的說明爲bgplot3d頁:

因爲背景圖繪製成位圖,他們不調整 非常優雅。最好首先確定窗口的大小,然後繪製該尺寸的背景圖案 。