Posted  by  admin

3 Plots In R

[This article was first published on Revolutions, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Plot3D, from Karline Soetaert, is an R package containing many functions for 2D and 3D plotting: scatter3D, points3D, lines3D, text3D, ribbon3d, hist3D, etc. In addition to the x, y (and z) values, an additional data dimension can be represented by a color variable (argument colvar). Step 3: Produce a Q-Q plot. We can also produce a Q-Q plot, which is useful for determining if the residuals follow a normal distribution. If the data values in the plot fall along a roughly straight line at a 45-degree angle, then the data is normally distributed.

by Joseph Rickert

Recently, I was trying to remember how to make a 3D scatter plot in R when it occurred to me that the documentation on how to do this is scattered all over the place. Hence, this short organizational note that you may find useful.

3 Plots In R

First of all, for the benefit of newcomers, I should mention that R has three distinct graphics systems: (1) the “traditional” graphics system, (2) the grid graphics system and (3) ggplot2. The traditional graphic system refers to the graphics and plotting functions in base R. According to Paul Murrell’s authoritative R Graphics, these functions implement the graphics facilities of the S language, and up to about 2005 they comprised most of the graphics functionality of R. The grid graphics system is based on Deepayan Sarkar’s lattice package which implements the functionality of Bill Cleveland’s Trellis graphics. Finally, ggplot2 Hadley Wickham’s package based on Wilkinson's Grammar of Graphics, took shape between 2007 and 2009 when ggplot2 Elegant Graphics for Data Analysis appeared.

There is considerable overlap of the functionality of R’s three graphics systems, but each has its own strengths and weaknesses. For example, although ggplot2 is currently probably the most popular R package for doing presentation quality plots it does not offer 3D plots. To work effectively in R I think it is necessary to know your way around at least two of the graphics systems. To really gain a command of the visualizations that can be done in R, a person would have to be familiar with all three systems as well as the many packages for specialized visualizations: maps, social networks, arc diagrams, animations, time series etc.

But back to the relatively tame task of 3D plots: the generic function persp() in the base graphics package draws perspective plots of a surface over the x–y plane. Typing demo(persp) at the console will give you an idea of what this function can do.

3 Plots In R

The plot3D package from Karline Soetaert builds on on persp()to provide functions for both 2D and 3D plotting. The vignette for plot3D shows some very impressive plots. Load the package and type the following commands at the console: example(persp3D), example(surf3D) and example(scatter3D) to see examples of 3D surface and scatter plots. Also, try this code to see a cut-away view of a Torus.

The scatterplot3d package from R core members Uwe Ligges and Martin Machler is the 'go-to' package for 3D scatter plots. The vignette for this package is shows a rich array of plots. Load this package and type example(scatterplot3d) at the console to see examples of spirals, surfaces and 3D scatterplots.

The lattice package has its own distinctive look. Once you see one lattice plot it should be pretty easy to distinguish plots made with this package from base graphics plots. Load the packate and type example(cloud) in the console to see a 3D graph of a volcano, and 3D surface and scatter plots.

rgl from Daniel Adler and Duncan Murdoch and Rcmdr from John Fox et al. both allow interactive 3D vizualizations. Load the rgl package and type example(plot3d) to see a very cool, OpenGL, 3D scatter plot that you can grab with your mouse and rotate.

For additional references, see the scatterplot page of Robert Kabacoff's always helpful Quick-R site, and Paul E. Johnson's 3D Plotting presentation.

Related

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

Plot 3 Columns In R

R-bloggers.com offers daily e-mail updates

3 Plots In R H

about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job. Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.