rgl

3D Plotting in R - Using a 4th dimension of color

人走茶凉 提交于 2019-11-29 01:01:34
问题 I am using the plot3d function to make a 3d plot in my R script. I'd like to add a 4th dimension, which will be color. How can I do this? Specifically, assume I have the following code: plot3d(x, y, z, col=cols, size=2, type='s') how would I populate cols based on a vector of values acting as my 4th dimension. 回答1: Just make a colormap, and then index into it with a cut version of your c variable: x = rnorm(100) y = rnorm(100) z = rnorm(100) c = z c = cut(c, breaks=64) cols = rainbow(64)[as

Save the orientation of a RGL plot3d() plot

孤街醉人 提交于 2019-11-28 21:05:32
问题 I have a 3D plot using RGL. I would like to make identical plots using color to highlight the distribution of some variable. To do this I would like to have identical plots, how do I find and set the orientation of a plot? Once I make a preliminary plot, I move it around to find a nice display angle and I would like to save that angle and incorporate it into future plotting scripts. Anyone have a suggestion on how to do this? library(rgl) plot3d(iris) #play with the plot to find a good angle

How do I install the R package rgl on Ubuntu 9.10, using R version 2.12.1?

你说的曾经没有我的故事 提交于 2019-11-28 20:54:26
I'm trying to install the R package rgl on Ubuntu 9.10. I'm using R version 2.12.1. I got the following error: "configure: error: missing required header GL/gl.h" Edit: My original question did not specify that the operating system must be Ubuntu 9.10. I gather that otherwise it would be a good idea to update R, but that this cannot be done on Ubuntu 9.10. Because I'm stupid, I posted a new question instead of editing this one, so some discussion has occurred there. I had to deal with this problem many times, and this always worked just fine: type in a terminal sudo apt-get install libglu1

3d surface plot with xyz coordinates

风格不统一 提交于 2019-11-28 16:00:32
问题 I am hoping someone with experience can help in how one prepares the shape files from xyz data. A great example of a well-prepared dataset can be seen here for the comet Churyumov–Gerasimenko, although the preceding steps in creating the shape file are not provided. I'm trying to better understand how to apply a surface to a given set of XYZ coordinates. Using Cartesian coordinates is straight forward with the R package "rgl", however shapes that wrap around seem more difficult. I found the R

Plot 3D plane (true regression surface)

偶尔善良 提交于 2019-11-28 07:51:47
I'm trying to simulate some data (x1 and x2 - my explanatory variables), calculate y using a specified function + random noise and plot the resulting observations AND the true regression surface. Here's what I have so far: set.seed(1) library(rgl) # Simulate some data x1 <- runif(50) x2 <- runif(50) y <- sin(x1)*x2+x1*x2 + rnorm(50, sd=0.3) # 3D scatterplot of observations plot3d(x1,x2,y, type="p", col="red", xlab="X1", ylab="X2", zlab="Y", site=5, lwd=15) Now I'm not sure how I can add the "true" regression plane. I'm basically looking for something like curve() where I can plug in my (true)

R: using rgl to generate 3d rotatable plots that can be viewed in a web browser?

拟墨画扇 提交于 2019-11-28 05:22:38
In the world of the R statistics package, rgl allows me to generate 3d plots that I can rotate with my mouse. Is there a way I can export these plots in a portable format, load them in a web browser or other third party tool and rotate them there? I Am especially interested in the web browser solution since this will allow me to share the plots on an internal wiki. If rgl does not allow this, are there other libraries or strategies that would allow me to accomplish this? You could try the vrmlgen package. It will produce 3d VRML files that can be displayed with a browser plugin; you can find a

3D equivalent of the curve function in R?

江枫思渺然 提交于 2019-11-28 01:07:21
The curve function in R provides a simple way to plot a function. For example, this will plot a straight line f1 <- function(x) x curve(f1, from=-1, to=1) Is there an equivalent function in R which takes a function with two argument (e.g., x and y ) and ranges for both variables and produces a 3D plot? For example, imagine I had the following function f2 <- function(x, y) x + y Is there a command similar to the following? curve_3d(f2, x_range=c(-1, 1), y_range=c(-1, 1)) The surface3d function in package:rgl looks like a good match. It would be very simple to create a wrapper that would take

How do I install the R package rgl on Ubuntu 9.10, using R version 2.12.1?

你说的曾经没有我的故事 提交于 2019-11-27 13:16:08
问题 I'm trying to install the R package rgl on Ubuntu 9.10. I'm using R version 2.12.1. I got the following error: "configure: error: missing required header GL/gl.h" Edit: My original question did not specify that the operating system must be Ubuntu 9.10. I gather that otherwise it would be a good idea to update R, but that this cannot be done on Ubuntu 9.10. Because I'm stupid, I posted a new question instead of editing this one, so some discussion has occurred there. 回答1: I had to deal with

Error in loading rgl package with Mac OS X

此生再无相见时 提交于 2019-11-27 08:53:02
I am trying to install rgl package (0.92.858) for R (2.14.2) under Mac OS X (Lion 10.7.3). When I try to load it (library(rgl)), I get the following error: Error : .onLoad failed in loadNamespace() for 'rgl', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so': dlopen(/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rgl/libs/x86_64/aglrgl.so, 6): Symbol not found: __ZN3gui13OSXGUIFactory12hasEventLoopEv Referenced from: /Library/Frameworks/R.framework

including a interactive 3D figure with knitr

て烟熏妆下的殇ゞ 提交于 2019-11-27 06:23:24
Using knitr it is possible to embed a rgl 3D graphics in a html document from a Rmarkdown source file: ```{r setup} library(rgl) knit_hooks$set(rgl = hook_rgl) x <- sort(rnorm(1000)) y <- rnorm(1000) z <- rnorm(1000) + atan2(x,y) ``` ```{r, rgl=TRUE} plot3d(x, y, z, col=rainbow(1000)) ``` But the 3D graphic is not interactive in the html document. Is it possible to get an interactive 3D graphic ? The writeWebGL() function of the rgl package creates a html file with an interactive 3D graphic, is there a way to include directly this html code with Rmarkdown ? Otherwise how to include this html