just_rookie
2015-Jul-10 12:43 UTC
[R] how to embed a 3D plot created by “rgl” into "gWidgets ggraphics device“?
I created some 3D cubes by using "rgl" package. The next step is to embed the 3D plot("rgl" device) into "ggraphics" device from the "gWidgets" package, but I have no idea how to implement it. Is there a way to implement by "gWidgets" or other package? Any help? Thank you in advance! My code: library(rgl) library(scatterplot3d) library(gWidgets) options(guiToolkit="RGtk2") df<-data.frame(x=c(1,2,3,4), y=c(2,4,6,8), z=c(3,6,9,12), value=c(33,43,75,21)) clr <- df$value/max(df$value) f <- colorRamp(c("green", "yellow", "purple", "red")) ## 3D PLOT for(i in 1:length(df$x)){ shade3d(translate3d(scale3d(cube3d(col=rgb(f(clr[i])/255),alpha=0.15 ), 10.0, 10.0, 2.5),df$x[i],df$y[i],df$z[i])) } window <- gwindow("TEST", width = 800, height= 600, visible = FALSE) group <- ggroup(cont = window, expand = TRUE) loadBtn <- gbutton("display", cont = group) addHandlerChanged(loadBtn, handler = function(h,...){ sudwin<-gwindow("3D",visible = TRUE) dev <- ggraphics(cont=subwin) #### DO NOT KNOW HOW TO DO NEXT... }) visible(window)<-TRUE
Duncan Murdoch
2015-Jul-10 18:44 UTC
[R] how to embed a 3D plot created by “rgl” into "gWidgets ggraphics device“?
On 10/07/2015 8:43 AM, just_rookie wrote:> I created some 3D cubes by using "rgl" package. The next step is to embed the 3D plot("rgl" device) into "ggraphics" device from the "gWidgets" package, but I have no idea how to implement it. Is there a way to implement by "gWidgets" or other package? Any help? Thank you in advance!Is there an existing widget that displays HTML, and can display WebGL? Then it's probably easiest to use rgl::writeWebGL to create the Javascript code, and that other widget to display it. If you want it displayed using native OpenGL code, it's likely a lot more work. On Windows it's probably easiest; I don't know how hard it would be to do on other platforms. I would not personally spend any time on it. Duncan Murdoch> My code: > library(rgl) > library(scatterplot3d) > library(gWidgets) > options(guiToolkit="RGtk2") > > > df<-data.frame(x=c(1,2,3,4), > y=c(2,4,6,8), > z=c(3,6,9,12), > value=c(33,43,75,21)) > > clr <- df$value/max(df$value) > f <- colorRamp(c("green", "yellow", "purple", "red")) > > ## 3D PLOT > for(i in 1:length(df$x)){ > shade3d(translate3d(scale3d(cube3d(col=rgb(f(clr[i])/255),alpha=0.15 ), > 10.0, 10.0, 2.5),df$x[i],df$y[i],df$z[i])) > } > > window <- gwindow("TEST", width = 800, height= 600, visible = FALSE) > group <- ggroup(cont = window, expand = TRUE) > > loadBtn <- gbutton("display", cont = group) > > addHandlerChanged(loadBtn, handler = function(h,...){ > sudwin<-gwindow("3D",visible = TRUE) > dev <- ggraphics(cont=subwin) > #### DO NOT KNOW HOW TO DO NEXT... > }) > visible(window)<-TRUE > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >