i can visualise 3d shapes from 2d drawings

  • Install plot3D package
  • Load plot3D package
  • Fix the information
  • Scatter plots
    • Functions for scatter plots and texts in 2d and 3D
    • Basic scatter plot
    • Modify the type of the box around the plot
    • Colour palettes
    • Modify the color by groups
    • Change the position of the legend
    • 3D viewing direction
    • Titles and centrality labels
    • Tick marks and labels
    • Add points and text to an existing plot
  • Line plots
    • Add together confidence interval
    • 3D fancy Scatter plot with minor dots on basal airplane
    • Regression plane
  • text3D: plot three-dimensionnal texts
  • text3D and scatter3D
  • 3D Histogram
  • scatter2D: 2D scatter plot
  • text2D
  • Other functions
  • Interactive plot
  • Infos

In my previous manufactures, I already described how to brand 3D graphs in R using the parcel below:

  • scatterplot3d, non interactive
  • scatter3d, interactive
  • rgl, interactive

To close the discussion about 3D, in this tutorial I'll describe the impressive plot3D package and its extension plot3Drgl packet.

plot3D, from Karline Soetaert, is an R package containing many functions for 2D and 3D plotting: scatter3D, points3D, lines3D,text3D, ribbon3d, hist3D, etc.

In improver to the 10, y (and z) values, an additional data dimension can be represented by a colour variable (statement colvar).

This "4D" plot (x, y, z, color) with a color fable is not (easily) possible using the packages mentioned above (scatterplot3d, scatter3d, rgl).

The package plot3Drgl allows to plot easily the graph generated with plot3D in openGL, as made available by parcel rgl. This is described at the finish of the present article.

Install plot3D package

            install.packages("plot3D")          

Load plot3D package

            library("plot3D")          

Set the data

We'll use the iris data set in the following examples :

            data(iris) head(iris)          
                          Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1          5.one         3.5          1.4         0.ii  setosa ii          4.nine         iii.0          i.four         0.2  setosa 3          four.7         3.2          1.3         0.2  setosa 4          4.6         3.1          1.5         0.2  setosa 5          5.0         3.half-dozen          1.iv         0.2  setosa 6          v.4         3.nine          1.7         0.four  setosa          
            # x, y and z coordinates x <- sep.fifty <- iris$Sepal.Length y <- pet.l <- iris$Petal.Length z <- sep.west <- iris$Sepal.Width          

iris data set gives the measurements of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica.

Besprinkle plots

Functions for scatter plots and texts in 2D and 3D

The function beneath will be used:

              scatter3D(x, y, z, ..., colvar = z, col = Nil, add together = FALSE) text3D(ten, y, z, labels, colvar = Zip, add = False) points3D(x, y, z, ...) lines3D(x, y, z, ...) scatter2D(10, y, colvar = NULL, col = NULL, add = Faux) text2D(10, y, labels, colvar = Goose egg, col = Naught, add = FALSE)            

  • x, y, z: vectors of signal coordinates
  • colvar: a variable used for coloring
  • col: color palette used for coloring the colvar variable
  • labels: the text to be written
  • add together: logical. If TRUE, then the points volition be added to the current plot. If FALSE a new plot is started
  • : boosted persp arguments including xlim, ylim, zlim, xlab, ylab, zlab, chief, sub, r, d, scale, aggrandize, box, axes, nticks, tictype.

Note that:

  • points3D and lines3D are shorthand for scatter3D(…, type ="p") and scatter3D(…, type = "50"), respectively.
  • points2D and lines2D are shorthand for scatter2D(…, type = "p") and scatter2D(…, blazon ="50"), respectively.

Bones scatter plot

              scatter3D(ten, y, z, clab = c("Sepal", "Width (cm)"))            

plot3D - R software and data visualization

The argument clab is used to alter the championship of the color legend.

By default, the points are colored automatically using the variable Z

In the R code below:

  • colvar = NULL: avoids coloring by z variable
  • col = "bluish": changes point colors to blue
  • pch = 19: changes point shapes
  • cex = 0.5: changes the size of points
              scatter3D(x, y, z, colvar = Goose egg, col = "blue",           pch = 19, cex = 0.v)            

plot3D - R software and data visualization

Change the type of the box around the plot

The argument bty is used. Allowed values are:

  • "f": full box
  • "b": default value. Simply the dorsum panels are visible
  • "b2": back panels and filigree lines are visible
  • "g": grayness background with white grid lines
  • "bl": black groundwork
  • "bl2": black groundwork with greyness lines
  • "u": means that the user will specify the arguments col.axis, col.panel, lwd.panel, col.grid, lwd.grid manually
  • "n": no box will be drawn. This is the same as setting box = FALSE
              # full box scatter3D(x, y, z, bty = "f", colkey = FALSE, chief ="bty= 'f'") # back panels and grid lines are visible scatter3D(ten, y, z, bty = "b2", colkey = FALSE, main ="bty= 'b2'" )            

plot3D - R software and data visualization plot3D - R software and data visualization

              # greyness background with white grid lines scatter3D(x, y, z, bty = "yard", colkey = FALSE, chief ="bty= 'one thousand'") # User defined scatter3D(ten, y, z, pch = 18, bty = "u", colkey = FALSE,     master ="bty= 'u'", col.panel ="steelblue", expand =0.4,     col.filigree = "darkblue")            

plot3D - R software and data visualization plot3D - R software and data visualization

The argument colkey = Imitation is used to remove the fable.

Colour palettes

Several color palettes are available in plot3D bundle:

  • jet.col(n, alpha): generates the matlab-type colors. This is the default colour palette used in plot3D
  • jet2.col(n, blastoff): like to jet.col() just lacks the deep blue colors
  • gg.col(n, alpha) and gg2.col(north, alpha) generates gg-plot-like colors
  • ramp.col(col = c("grey", "black"), n, alpha): creates color schemes past interpolation
  • alpha.col(col = "grey", blastoff): creates transparent colors

  • n: Number of colors to generate. Default value is 100
  • alpha: color transparency. Value in the range 0, 1. Default value is 1
  • col: Colors to interpolate
              # gg.col: ggplot2 like color scatter3D(x, y, z, bty = "g", pch = 18, col = gg.col(100)) # ramp.col: custom palettes scatter3D(x, y, z, bty = "thousand", pch = 18,           col = ramp.col(c("bluish", "yellowish", "red")) )            

plot3D - R software and data visualization plot3D - R software and data visualization

Change the color by groups

The colkey is customized (see ?colkey for more details):

              scatter3D(ten, y, z, bty = "g", pch = 18,            col.var = equally.integer(iris$Species),            col = c("#1B9E77", "#D95F02", "#7570B3"),           pch = eighteen, ticktype = "detailed",           colkey = list(at = c(2, iii, 4), side = i,            addlines = True, length = 0.5, width = 0.5,           labels = c("setosa", "versicolor", "virginica")) )            

plot3D - R software and data visualization

Change the position of the legend

              # Bottom colkey scatter3D(x, y, z, bty = "g",           colkey = list(side = ane, length = 0.5))            

plot3D - R software and data visualization

The statement side is used to specify the colkey position: ane: for lesser, 2: for left, 3: for top, 4: for right.

3D viewing direction

The arguments theta and phi can exist used to define the angles for the viewing management. theta is the azimuthal direction and phi the co-latitude.

              scatter3D(x, y, z, theta = 15, phi = 20)            

plot3D - R software and data visualization

              scatter3D(x, y, z, phi = 0, bty ="thousand")            

plot3D - R software and data visualization

The default values for theta and phi are 40.

Titles and axis labels

              scatter3D(x, y, z, pch = 18,  theta = xx, phi = 20,           main = "Iris data", xlab = "Sepal.Length",           ylab ="Petal.Length", zlab = "Sepal.Width")            

plot3D - R software and data visualization

Tick marks and labels

The arguments beneath can be used:

  1. ticktype: Possible values are
  • "uncomplicated" draws merely an arrow parallel to the axis to point direction of increase
  • "detailed" draws normal ticks and labels
  1. nticks: the number of tick marks to depict on the axes. It has no consequence if ticktype ="simple".
                              scatter3D(10, y, z, phi = 0, bty = "g",         pch = xx, cex = ii, ticktype = "detailed")            

plot3D - R software and data visualization

Add points and text to an existing plot

The functions beneath can be used:

  • scatter3D(ten, y, z,…, add = True): Adds points
  • text3D(ten, y, z, labels, …, add together = True): Adds texts
  1. Add together points to an existing plot:
              # Create a scatter plot  scatter3D(10, y, z, phi = 0, bty = "one thousand",         pch = twenty, cex = 2, ticktype = "detailed") # Add another bespeak (black color) scatter3D(ten = 7, y = iii, z = 3.v, add = True, colkey = FALSE,           pch = eighteen, cex = three, col = "black")            

plot3D - R software and data visualization

  1. Add texts to an existing plot:
              # Create a besprinkle plot  scatter3D(x, y, z, phi = 0, bty = "1000", pch = 20, cex = 0.5) # Add text text3D(x, y, z,  labels = rownames(iris),         add = True, colkey = Imitation, cex = 0.5)            

plot3D - R software and data visualization

Line plots

            # type ="l" for lines merely  scatter3D(x, y, z, phi = 0, bty = "one thousand", type = "fifty",             ticktype = "detailed", lwd = four)          

plot3D - R software and data visualization

            # type ="b" for both points and lines  scatter3D(10, y, z, phi = 0, bty = "grand", type = "b",             ticktype = "detailed", pch = xx,             cex = c(0.five, ane, i.5))          

plot3D - R software and data visualization

            # blazon ="h" for vertical lines scatter3D(x, y, z, phi = 0, bty = "chiliad",  blazon = "h",             ticktype = "detailed", pch = nineteen, cex = 0.5)          

plot3D - R software and data visualization

Vertical lines are useful to encounter clearly the x-y location of points.

Add confidence interval

The argument CI is used. It's a list containing the parameters and values for the confidence intervals or NULL.


If CI is a listing, it should contain at least the item x, y or z (latter for scatter3D).These should exist ii-columned matrices, defining the left/correct intervals.

Other parameters should be ane of: alen = 0.01, lty = par("lty"), lwd = par("lwd"), col = Goose egg, to set the length of the arrow head, the line blazon and width, and the color.

If col is Null, and then the colors as specified by colvar are used.

              # Confidence interval CI <- list(z = matrix(nrow = length(x),                     data = rep(0.ane, 2*length(x)))) head(CI$z)            
                              [,one] [,2] [1,]  0.1  0.1 [2,]  0.ane  0.i [3,]  0.ane  0.one [4,]  0.i  0.1 [five,]  0.1  0.one [half dozen,]  0.i  0.ane            
              # 3D Scatter plot with CI scatter3D(x, y, z, phi = 0, bty = "g", col = gg.col(100),            pch = 18, CI = CI)            

plot3D - R software and data visualization

3D fancy Scatter plot with small dots on basal airplane

A helper function scatter3D_fancy() is used:

              # Add pocket-sized dots on basal aeroplane and on the depth plane scatter3D_fancy <- function(ten, y, z,..., colvar = z)   {    panelfirst <- role(pmat) {       XY <- trans3D(ten, y, z = rep(min(z), length(z)), pmat = pmat)       scatter2D(XY$x, XY$y, colvar = colvar, pch = ".",                cex = 2, add = TRUE, colkey = FALSE)           XY <- trans3D(x = rep(min(ten), length(ten)), y, z, pmat = pmat)       scatter2D(XY$x, XY$y, colvar = colvar, pch = ".",                cex = ii, add = True, colkey = Imitation)   }   scatter3D(x, y, z, ..., colvar = colvar, panel.first=panelfirst,     colkey = listing(length = 0.5, width = 0.5, cex.clab = 0.75))  }            

Fancy besprinkle plot:

              scatter3D_fancy(x, y, z, pch = 16,     ticktype = "detailed", theta = fifteen, d = two,     primary = "Iris information",  clab = c("Petal", "Width (cm)") )            

plot3D - R software and data visualization

Regression plane

The mtcars data volition be used:

              data(mtcars) caput(mtcars[, 1:6])            
                              mpg cyl disp  hp drat    wt Mazda RX4         21.0   vi  160 110 3.xc 2.620 Mazda RX4 Wag     21.0   half dozen  160 110 3.ninety 2.875 Datsun 710        22.8   4  108  93 3.85 2.320 Hornet iv Bulldoze    21.4   6  258 110 3.08 3.215 Hornet Sportabout 18.vii   8  360 175 iii.xv 3.440 Valiant           18.1   6  225 105 2.76 3.460            
  1. Utilize the role lm() to compute a linear regression model: ax + by + cz + d = 0
  2. Use the statement surf in scatter3D() part to add a regression surface.
              # x, y, z variables x <- mtcars$wt y <- mtcars$disp z <- mtcars$mpg # Compute the linear regression (z = ax + past + d) fit <- lm(z ~ x + y) # predict values on regular xy grid grid.lines = 26 x.pred <- seq(min(x), max(x), length.out = grid.lines) y.pred <- seq(min(y), max(y), length.out = filigree.lines) xy <- expand.filigree( x = ten.pred, y = y.pred) z.pred <- matrix(predict(fit, newdata = xy),                   nrow = grid.lines, ncol = grid.lines) # fitted points for droplines to surface fitpoints <- predict(fit) # scatter plot with regression airplane scatter3D(ten, y, z, pch = 18, cex = 2,      theta = twenty, phi = 20, ticktype = "detailed",     xlab = "wt", ylab = "disp", zlab = "mpg",       surf = listing(x = ten.pred, y = y.pred, z = z.pred,       facets = NA, fit = fitpoints), main = "mtcars")            

plot3D - R software and data visualization

surf is a list specifying a (fitted) surface to be added on the besprinkle plot. The list should include at to the lowest degree x, y, z, defining the surface.

Other optional parameters can exist specified in the surf argument including: colvar, col, NAcol, edge, facets, lwd, resfac, clim, ltheta, lphi, shade, lighting, fit. (run into ?surf3D for more details on these parameters)


  • Note that, by default colvar = z.

  • The argument fit should give the fitted z-values, in the same order as the z-values of the scatter points, for instance produced past predict(). When present, this will produce droplines from points to the fitted surface.

Notation that, the function expand.filigree(), in the R code higher up, creates a data frame from all combinations of factors

text3D: plot 3-dimensionnal texts

The function text3D() is used as follow:

            text3D(ten, y, z, labels, ...)          

The USArrests data sets will be used in the example below:

            data(USArrests) with(USArrests, text3D(Murder, Assault, Rape,    labels = rownames(USArrests), colvar = UrbanPop,    col = gg.col(100), theta = 60, phi = twenty,   xlab = "Murder", ylab = "Assault", zlab = "Rape",    chief = "USA arrests", cex = 0.6,    bty = "thou", ticktype = "detailed", d = two,   clab = c("Urban","Popular"), adj = 0.5, font = 2))          

plot3D - R software and data visualization

text3D and scatter3D

            # Plot texts with(USArrests, text3D(Murder, Assault, Rape,    labels = rownames(USArrests), colvar = UrbanPop,    col = gg.col(100), theta = lx, phi = 20,   xlab = "Murder", ylab = "Assail", zlab = "Rape",    main = "The states arrests", cex = 0.6,    bty = "grand", ticktype = "detailed", d = 2,   clab = c("Urban","Pop"), adj = 0.v, font = 2)) # Add points  with(USArrests, scatter3D(Murder, Assail, Rape - 1,      colvar = UrbanPop, col = gg.col(100),      type = "h", pch = ".", add = TRUE))          

plot3D - R software and data visualization

            # Zoom near origin: choose suitable ranges  plotdev(xlim = c(0, x), ylim = c(40, 150),           zlim = c(7, 25))          

plot3D - R software and data visualization


Note that, in order to choose suitable ranges for zooming, y'all tin can display axis ranges as follow:

              # display axis ranges  getplist()[c("xlim","ylim","zlim")]                          
              $xlim [i]  0.8 17.4 $ylim [i]  45 337 $zlim [one]  7.3 46.0            

3D Histogram

The function hist3D() is used:

            hist3D (x, y, z, ..., colvar = z,        col = Nothing,  add = FALSE)                      

  • z: Matrix containing the values to be plotted
  • x, y vectors with ten and y values. x should be of length equal to nrow(z) and y should be equal to ncol(z)
  • colvar: the variable used for coloring. If present, it should have the same dimension as z.
  • col: colour palette to be used for the colvar variable. By default a cherry-xanthous-blue colour scheme (?jet.col) is used
  • add: Logical. If True, and so the surfaces will be added to the current plot. If FALSE a new plot is started.
            data(VADeaths) #  hist3D and ribbon3D with greyish background, rotated, rescaled,... hist3D(z = VADeaths, scale = FALSE, expand = 0.01, bty = "thousand", phi = 20,         col = "#0072B2", edge = "black", shade = 0.two, ltheta = 90,         space = 0.3, ticktype = "detailed", d = two)          

plot3D - R software and data visualization

            hist3D (x = ane:5, y = ane:4, z = VADeaths,         bty = "grand", phi = 20,  theta = -threescore,         xlab = "", ylab = "", zlab = "", principal = "VADeaths",         col = "#0072B2", border = "black", shade = 0.eight,         ticktype = "detailed", space = 0.xv, d = 2, cex.axis = 1e-9) # Use text3D to characterization x axis  text3D(x = 1:5, y = rep(0.5, v), z = rep(three, 5),        labels = rownames(VADeaths),        add together = TRUE, adj = 0) # Use text3D to label y centrality  text3D(x = rep(1, 4),   y = 1:4, z = rep(0, 4),        labels  = colnames(VADeaths),        add = TRUE, adj = 1)          

plot3D - R software and data visualization

fancy 3D histograms

            hist3D_fancy<- function(x, y, interruption.func = c("Sturges", "scott", "FD"), breaks = NULL,                         colvar = Cipher, col="white", clab=Naught, phi = 5, theta = 25, ...){      # Compute the number of classes for a histogram   break.func <- suspension.func [1]   if(is.zippo(breaks)){     10.breaks <- switch(suspension.func,                        Sturges = nclass.Sturges(x),                        scott = nclass.scott(x),                        FD = nclass.FD(x))     y.breaks <- switch(break.func,                        Sturges = nclass.Sturges(y),                        scott = nclass.scott(y),                        FD = nclass.FD(y))   } else x.breaks <- y.breaks <- breaks      # Cut 10 and y variables in bins for counting   x.bin <- seq(min(x), max(10), length.out = ten.breaks)   y.bin <- seq(min(y), max(y), length.out = y.breaks)   xy <- table(cut(x, 10.bin), cut(y, y.bin))   z <- xy      xmid <- 0.v*(x.bin[-i] + x.bin[-length(ten.bin)])   ymid <- 0.v*(y.bin[-ane] + y.bin[-length(y.bin)])      oldmar <- par("mar")   par (mar = par("mar") + c(0, 0, 0, 2))   hist3D(ten = xmid, y = ymid, z = xy, ...,     zlim = c(-max(z)/2, max(z)), zlab = "counts", bty= "k",      phi = phi, theta = theta,     shade = 0.2, col = col, border = "black",     d = 1, ticktype = "detailed")       scatter3D(x, y,     z = rep(-max(z)/2, length.out = length(x)),     colvar = colvar, col = gg.col(100),     add = True, pch = eighteen, clab = clab,     colkey = list(length = 0.5, width = 0.five,        dist = 0.05, cex.centrality = 0.8, cex.clab = 0.8)        )   par(mar = oldmar) }          
            hist3D_fancy(quakes$long, quakes$lat, colvar=quakes$depth,              breaks =thirty)          

plot3D - R software and data visualization

            hist3D_fancy(iris$Sepal.Length, iris$Petal.Width,               colvar=as.numeric(iris$Species))          

plot3D - R software and data visualization

scatter2D: 2D scatter plot

Create some information:

            # x, y coordinates gear up.seed(1234) x  <- sort(rnorm(x))  y  <- runif(10) # Variable for coloring points col.v <- sqrt(10^2 + y^2)                      

Basic 2nd scatter plot:

            scatter2D(10, y, colvar = col.v, pch = 16, bty ="n",           type ="b")          

plot3D - R software and data visualization


  1. type: plot types. Allowed values are:
  • "b" to draw both points and line
  • "h" for vertical line
  • "l" for line only
  • "p" for points only
  1. bty: box type

2D scatter plot with confidence interval:

            # Confidence interval for ten variable only CI <- list() CI$x <- matrix(nrow = length(ten), data = c(rep(0.25, 2*length(x)))) scatter2D(x, y, colvar = col.5, pch = 16, bty ="n", cex = 1.5,            CI = CI, type = "b")          

plot3D - R software and data visualization

            # Confidence interval for both x and y variables CI$y <- matrix (nrow = length(y), information = c(rep(0.05, 2*length(y)))) CI$col <- "black" scatter2D(x, y, colvar = col.v, pch = 16,  bty ="n", cex = 1.five,           CI = CI, blazon ="b")          

plot3D - R software and data visualization

            CI$y[c(two,4,8,ten), ] <- NA  # Some points have no CI CI$x[c(ii,iv,viii,10), ] <- NA  # Some points have no CI CI$alen <- 0.02            # increase arrow head scatter2D(x, y, colvar = col.v, pch = sixteen,  bty ="n", cex = one.v,           CI = CI, blazon ="b")          

plot3D - R software and data visualization

text2D

            # Just text with(USArrests, text2D(x = Murder, y = Assault + 5, colvar = Rape,       xlab = "Murder", ylab = "Assault", clab = "Rape",       main = "Us arrests", labels = rownames(USArrests), cex = 0.6,       adj = 0.5, font = two))          

plot3D - R software and data visualization

            # text with bespeak  with(USArrests, text2D(x = Murder, y = Attack + five, colvar = Rape,       xlab = "Murder", ylab = "Attack", clab = "Rape",       principal = "Us arrests", labels = rownames(USArrests), cex = 0.half dozen,       adj = 0.5, font = 2))  with(USArrests, scatter2D(x = Murder, y = Set on, colvar = Rape,       pch = xvi, add = TRUE, colkey = False))          

plot3D - R software and data visualization

Other functions

It'southward also possible to draw arrows, segments and rectangles in a 3D or 2D plot using the functions below:

            arrows3D(x0, y0, z0, x1, y1, z1, ..., colvar = NULL,          col = Zip, type = "triangle", add = Faux) segments3D(x0, y0, z0, x1, y1, z1, ..., colvar = NULL,            col = NULL, add = "Imitation") rect3D(x0, y0, y0, x1, y1, z1, ..., colvar = NULL,        col = Zip, add = FALSE) arrows2D(x0, y0, z0, x1, y1, z1, ..., colvar = NULL,          col = NULL, type = "triangle", add = Simulated) segments2D(x0, y0, z0, x1, y1, z1, ..., colvar = Cypher,            col = NULL, add together = "FALSE") rect2D(x0, y0, y0, x1, y1, z1, ..., colvar = Aught,        col = Zilch, add = Imitation)          

  • x0, y0, z0: coordinates of points from which to describe
  • x1, y1, z1: coordinates of points to which to draw. For arrows3D and segments3D, at to the lowest degree one must be supplied. For rect3D exactly 1 must be NULL.
  • colvar: The variable used for coloring.
  • col: color palette to be used for coloring. Default is carmine-yellow-bluish color scheme.
  • add: Logical. If TRUE, and then the arrows, segments, … will exist added to the electric current plot. If Faux a new plot is started.

Prepare the information: we want to plot 4 arrows starting from the point of coordinates c(x0, y0, z0) and catastrophe at c(x1, y1, z1)

            x0 <- c(0, 0, 0, 0) y0 <- c(0, 0, 0, 0) z0 <- c(0, 0, 0, 0) x1 <- c(0.89, -0.46, 0.99, 0.96) y1 <- c(0.36,  0.88, 0.02, 0.06) z1 <- c(-0.28, 0.09, 0.05, 0.24) cols <- c("#1B9E77", "#D95F02", "#7570B3", "#E7298A")          

3D Arrows:

            arrows3D(x0, y0, z0, x1, y1, z1, colvar = x1^2, col = cols,          lwd = 2, d = 3, clab = c("Quality", "score"),           main = "Arrows 3D", bty ="one thousand", ticktype = "detailed") # Add starting bespeak of arrow points3D(x0, y0, z0, add = Truthful, col="darkred",            colkey = FALSE, pch = 19, cex = 1) # Add labels to the arrows text3D(x1, y1, z1, c("Sepal.Fifty", "Sepal.W", "Petal.L", "Petal.W"),        colvar = x1^ii, col = cols, add=TRUE, colkey = Fake)          

plot3D - R software and data visualization

2D arrows:

            arrows2D(x0, y0,  x1, y1,  colvar = x1^2, col = cols,          lwd = 2, clab = c("Quality", "score"),            bty ="n", xlim = c(-1, one), ylim = c(-1, 1)) # Add vertical and horizontal lines at c(0,0) abline(h =0, v = 0, lty = 2) # Add starting point of arrow points2D(x0, y0, add = Truthful, col="darkred",            colkey = FALSE, pch = 19, cex = 1) # Add labels to the arrows text2D(x1, y1, c("Sepal.Fifty", "Sepal.W", "Petal.L", "Petal.W"),        colvar = x1^ii, col = cols, add=Truthful, colkey = Fake)          

plot3D - R software and data visualization

Note that, segments3D() and segments2D() are very similar to arrows3D() and arrows2D() and you tin play with them also.

3D rectangle: the R lawmaking below creates a rectangle with a transparent fill color (blastoff = 0.5)

            rect3D(x0 = 0, y0 = 0.v, z0 = 0, x1 = 1, z1 = 5,         ylim = c(0, 1), bty = "g", facets = Truthful,         border = "red", col ="#7570B3", blastoff=0.5,        lwd = 2, phi = xx)          

plot3D - R software and data visualization

In the R code above, facets = FALSE, volition remove the rectangle fill color.

2d rectangle:

            rect2D(x0 = runif(3), y0 = runif(3),         x1 = runif(3), y1 = runif(three), colvar = 1:iii,         alpha = 0.4, lwd = 2, main = "rect2D")          

plot3D - R software and data visualization

Interactive plot

To describe an interactive 3D plot the parcel plot3Drgl can be used.

The package plot3Drgl allows to plot the graph generated with plot3D in openGL, as made available by bundle rgl.

The simplest fashion is to practice equally follow:

  1. Create base of operations R-graphics using plot3D parcel
  2. Then utilize the function plotrgl() to draw the same figure in rgl

The package rgl allows to interactively rotate, zoom the graphs. Even so it's not even so possible to plot a colorkey

            # Create his3D using plot3D hist3D_fancy(iris$Sepal.Length, iris$Petal.Width, colvar=as.numeric(iris$Species)) # Make the rgl version library("plot3Drgl") plotrgl()          

RGL movie 3d


Note that, after creating the rgl plot you can use the functions below:

  • croprgl(xlim, ylim, zlim, …) to change the ranges
  • cutrgl(…) to zoom in on a selected region of the plot. The current plot will exist overwritten
  • uncutrgl(…) and uncroprgl(…) restore the original plot.

  • …: whatever arguments for par3d, open3d or material3d in rgl packet.

This folio has been seen 457798 times

kellyintood1964.blogspot.com

Source: http://www.sthda.com/english/wiki/impressive-package-for-3d-and-4d-graph-r-software-and-data-visualization

0 Response to "i can visualise 3d shapes from 2d drawings"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel