Plotting randu dataset

November 18, 2011
By

(This article was first published on R snippets, and kindly contributed to R-bloggers)

Recently I have stumbled on help description of randu data from datasets package. It contains pseudorandom numbers that are flawed. Help says that “In three dimensional displays it is evident that the triples fall on 15 parallel planes in 3-space.. So I decided to generate the plot that would show this.


If you simply plot the data in 3D the result is not so obvious as can be seen on this picture:

However, using rgl package I managed to get the job done really fast. It allows for interactive rotation of the plot and one can easily find the appropriate viewpoint. The only obstacle is that in order to see all 15 lines on one view one needs to set filed-of-view to 0 to get orthogonal projection. Here is the code that generates the required plot:

library(rgl)
with(randu, plot3d(x, y, z, axes = FALSE,
                   xlab = “”, ylab = “”, zlab = “”))
rgl.viewpoint(theta = 3.8, phi = 3.8, fov = 0, zoom = 0.7)
rgl.snapshot(“randu.png”)

It generates the following result, nicely showing 15 parallel lines:

To leave a comment for the author, please follow the link and comment on their blog: R snippets.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)