how to draw 3d graph on graph paper

  • Install plot3D package
  • Load plot3D package
  • Fix the data
  • Scatter plots
    • Functions for besprinkle plots and texts in second and 3D
    • Basic scatter plot
    • Change the blazon of the box around the plot
    • Colour palettes
    • Change the color by groups
    • Modify 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 conviction interval
    • 3D fancy Scatter plot with small dots on basal plane
    • Regression plane
  • text3D: plot 3-dimensionnal texts
  • text3D and scatter3D
  • 3D Histogram
  • scatter2D: 2D scatter plot
  • text2D
  • Other functions
  • Interactive plot
  • Infos

In my previous articles, I already described how to make 3D graphs in R using the package below:

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

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

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 10, y (and z) values, an additional data dimension can be represented by a colour variable (argument colvar).

This "4D" plot (ten, y, z, color) with a color legend is non (hands) possible using the packages mentioned above (scatterplot3d, scatter3d, rgl).

The parcel plot3Drgl allows to plot easily the graph generated with plot3D in openGL, every bit made available by package rgl. This is described at the terminate of the nowadays article.

Install plot3D package

            install.packages("plot3D")          

Load plot3D bundle

            library("plot3D")          

Ready the data

Nosotros'll use the iris data set in the post-obit examples :

            data(iris) head(iris)          
                          Sepal.Length Sepal.Width Petal.Length Petal.Width Species one          five.ane         3.5          one.4         0.ii  setosa 2          4.ix         three.0          one.4         0.ii  setosa 3          4.7         3.2          1.3         0.2  setosa 4          4.half dozen         3.1          1.5         0.2  setosa 5          five.0         3.six          1.4         0.2  setosa 6          five.4         3.ix          1.7         0.4  setosa          
            # 10, y and z coordinates x <- sep.50 <- iris$Sepal.Length y <- pet.l <- iris$Petal.Length z <- sep.due west <- iris$Sepal.Width          

iris information 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.

Scatter plots

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

The function beneath will be used:

              scatter3D(10, y, z, ..., colvar = z, col = NULL, add = Faux) text3D(x, y, z, labels, colvar = NULL, add = FALSE) points3D(x, y, z, ...) lines3D(x, y, z, ...) scatter2D(x, y, colvar = Null, col = NULL, add = Faux) text2D(x, y, labels, colvar = NULL, col = NULL, add = Simulated)            

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

Notation that:

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

Bones besprinkle plot

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

plot3D - R software and data visualization

The statement clab is used to change the title 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 = "blue": changes bespeak colors to blueish
  • pch = 19: changes point shapes
  • cex = 0.5: changes the size of points
              scatter3D(x, y, z, colvar = Cypher, col = "blue",           pch = 19, cex = 0.5)            

plot3D - R software and data visualization

Change the blazon of the box around the plot

The statement bty is used. Allowed values are:

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

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

              # grey background with white filigree lines scatter3D(x, y, z, bty = "g", colkey = False, master ="bty= 'g'") # User defined scatter3D(x, y, z, pch = 18, bty = "u", colkey = FALSE,     principal ="bty= 'u'", col.panel ="steelblue", expand =0.iv,     col.grid = "darkblue")            

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

The argument colkey = Simulated is used to remove the legend.

Color palettes

Several colour palettes are bachelor in plot3D package:

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

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

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

Change the colour by groups

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

              scatter3D(x, y, z, bty = "g", pch = 18,            col.var = equally.integer(iris$Species),            col = c("#1B9E77", "#D95F02", "#7570B3"),           pch = 18, ticktype = "detailed",           colkey = listing(at = c(ii, 3, 4), side = 1,            addlines = TRUE, length = 0.v, 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 = 1, length = 0.5))            

plot3D - R software and data visualization

The argument side is used to specify the colkey position: 1: for bottom, 2: for left, three: for tiptop, 4: for right.

3D viewing management

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

              scatter3D(10, y, z, theta = 15, phi = twenty)            

plot3D - R software and data visualization

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

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 = twenty, phi = xx,           main = "Iris data", xlab = "Sepal.Length",           ylab ="Petal.Length", zlab = "Sepal.Width")            

plot3D - R software and data visualization

Tick marks and labels

The arguments below can be used:

  1. ticktype: Possible values are
  • "simple" draws just an arrow parallel to the axis to indicate management of increment
  • "detailed" draws normal ticks and labels
  1. nticks: the number of tick marks to depict on the axes. It has no issue if ticktype ="unproblematic".
                              scatter3D(ten, y, z, phi = 0, bty = "g",         pch = twenty, cex = 2, ticktype = "detailed")            

plot3D - R software and data visualization

Add points and text to an existing plot

The functions beneath can be used:

  • scatter3D(10, y, z,…, add = True): Adds points
  • text3D(10, y, z, labels, …, add = Truthful): Adds texts
  1. Add points to an existing plot:
              # Create a scatter plot  scatter3D(10, y, z, phi = 0, bty = "g",         pch = 20, cex = ii, ticktype = "detailed") # Add another point (black color) scatter3D(x = vii, y = 3, z = 3.five, add = TRUE, colkey = Simulated,           pch = 18, cex = iii, col = "blackness")            

plot3D - R software and data visualization

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

plot3D - R software and data visualization

Line plots

            # type ="l" for lines only  scatter3D(x, y, z, phi = 0, bty = "g", blazon = "l",             ticktype = "detailed", lwd = four)          

plot3D - R software and data visualization

            # type ="b" for both points and lines  scatter3D(x, y, z, phi = 0, bty = "g", type = "b",             ticktype = "detailed", pch = 20,             cex = c(0.5, 1, 1.5))          

plot3D - R software and data visualization

            # type ="h" for vertical lines scatter3D(x, y, z, phi = 0, bty = "g",  type = "h",             ticktype = "detailed", pch = xix, cex = 0.5)          

plot3D - R software and data visualization

Vertical lines are useful to run across conspicuously the 10-y location of points.

Add confidence interval

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


If CI is a list, it should contain at to the lowest degree the item 10, y or z (latter for scatter3D).These should be 2-columned matrices, defining the left/correct intervals.

Other parameters should exist i of: alen = 0.01, lty = par("lty"), lwd = par("lwd"), col = NULL, to set the length of the arrow head, the line type and width, and the color.

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

              # Conviction interval CI <- list(z = matrix(nrow = length(x),                     information = rep(0.ane, ii*length(x)))) head(CI$z)            
                              [,i] [,ii] [1,]  0.one  0.1 [ii,]  0.1  0.1 [three,]  0.1  0.ane [four,]  0.1  0.1 [5,]  0.1  0.1 [vi,]  0.1  0.i            
              # 3D Scatter plot with CI scatter3D(x, y, z, phi = 0, bty = "grand", col = gg.col(100),            pch = 18, CI = CI)            

plot3D - R software and data visualization

3D fancy Scatter plot with pocket-sized dots on basal plane

A helper function scatter3D_fancy() is used:

              # Add small dots on basal plane and on the depth plane scatter3D_fancy <- function(x, y, z,..., colvar = z)   {    panelfirst <- function(pmat) {       XY <- trans3D(ten, y, z = rep(min(z), length(z)), pmat = pmat)       scatter2D(XY$10, XY$y, colvar = colvar, pch = ".",                cex = 2, add = TRUE, colkey = Imitation)           XY <- trans3D(x = rep(min(x), length(x)), y, z, pmat = pmat)       scatter2D(XY$x, XY$y, colvar = colvar, pch = ".",                cex = 2, add together = TRUE, colkey = False)   }   scatter3D(x, y, z, ..., colvar = colvar, panel.beginning=panelfirst,     colkey = list(length = 0.5, width = 0.five, cex.clab = 0.75))  }            

Fancy besprinkle plot:

              scatter3D_fancy(x, y, z, pch = 16,     ticktype = "detailed", theta = 15, d = 2,     main = "Iris data",  clab = c("Petal", "Width (cm)") )            

plot3D - R software and data visualization

Regression plane

The mtcars information will be used:

              data(mtcars) caput(mtcars[, i:6])            
                              mpg cyl disp  hp drat    wt Mazda RX4         21.0   half dozen  160 110 3.90 2.620 Mazda RX4 Wag     21.0   half dozen  160 110 iii.ninety 2.875 Datsun 710        22.8   4  108  93 3.85 2.320 Hornet 4 Drive    21.4   6  258 110 3.08 3.215 Hornet Sportabout 18.7   8  360 175 3.xv 3.440 Valiant           18.one   6  225 105 2.76 3.460            
  1. Use the role lm() to compute a linear regression model: ax + past + cz + d = 0
  2. Use the statement surf in scatter3D() office to add a regression surface.
              # x, y, z variables 10 <- mtcars$wt y <- mtcars$disp z <- mtcars$mpg # Compute the linear regression (z = ax + by + d) fit <- lm(z ~ x + y) # predict values on regular xy grid grid.lines = 26 x.pred <- seq(min(10), max(x), length.out = grid.lines) y.pred <- seq(min(y), max(y), length.out = grid.lines) xy <- aggrandize.grid( ten = 10.pred, y = y.pred) z.pred <- matrix(predict(fit, newdata = xy),                   nrow = grid.lines, ncol = filigree.lines) # fitted points for droplines to surface fitpoints <- predict(fit) # scatter plot with regression airplane scatter3D(x, y, z, pch = xviii, cex = 2,      theta = 20, phi = 20, ticktype = "detailed",     xlab = "wt", ylab = "disp", zlab = "mpg",       surf = list(x = 10.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 scatter plot. The list should include at least x, y, z, defining the surface.

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


  • Annotation that, by default colvar = z.

  • The argument fit should requite the fitted z-values, in the aforementioned guild as the z-values of the besprinkle points, for instance produced by predict(). When nowadays, this will produce droplines from points to the fitted surface.

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

text3D: plot 3-dimensionnal texts

The part text3D() is used as follow:

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

The USArrests information sets will be used in the example beneath:

            information(USArrests) with(USArrests, text3D(Murder, Assault, Rape,    labels = rownames(USArrests), colvar = UrbanPop,    col = gg.col(100), theta = 60, phi = 20,   xlab = "Murder", ylab = "Assault", zlab = "Rape",    main = "United states arrests", cex = 0.6,    bty = "g", ticktype = "detailed", d = 2,   clab = c("Urban","Pop"), adj = 0.5, font = ii))          

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 = 60, phi = twenty,   xlab = "Murder", ylab = "Assault", zlab = "Rape",    main = "USA arrests", cex = 0.six,    bty = "g", 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, 10), ylim = c(forty, 150),           zlim = c(7, 25))          

plot3D - R software and data visualization


Note that, in order to choose suitable ranges for zooming, you lot can display axis ranges as follow:

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

3D Histogram

The function hist3D() is used:

            hist3D (10, y, z, ..., colvar = z,        col = Zip,  add = False)                      

  • z: Matrix containing the values to be plotted
  • x, y vectors with x and y values. ten should exist 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 every bit z.
  • col: color palette to be used for the colvar variable. Past default a red-yellow-blueish color scheme (?jet.col) is used
  • add: Logical. If Truthful, then the surfaces will be added to the current plot. If Faux a new plot is started.
            information(VADeaths) #  hist3D and ribbon3D with greyish groundwork, rotated, rescaled,... hist3D(z = VADeaths, scale = Faux, expand = 0.01, bty = "g", phi = twenty,         col = "#0072B2", border = "black", shade = 0.ii, ltheta = ninety,         space = 0.3, ticktype = "detailed", d = 2)          

plot3D - R software and data visualization

            hist3D (x = 1:5, y = 1:4, z = VADeaths,         bty = "thousand", phi = 20,  theta = -lx,         xlab = "", ylab = "", zlab = "", main = "VADeaths",         col = "#0072B2", edge = "black", shade = 0.8,         ticktype = "detailed", space = 0.15, d = 2, cex.centrality = 1e-9) # Use text3D to characterization x axis  text3D(ten = 1:5, y = rep(0.v, 5), z = rep(3, 5),        labels = rownames(VADeaths),        add = True, adj = 0) # Apply text3D to label y centrality  text3D(x = rep(1, iv),   y = 1:4, z = rep(0, 4),        labels  = colnames(VADeaths),        add together = TRUE, adj = 1)          

plot3D - R software and data visualization

fancy 3D histograms

            hist3D_fancy<- function(x, y, break.func = c("Sturges", "scott", "FD"), breaks = NULL,                         colvar = Nada, col="white", clab=NULL, phi = 5, theta = 25, ...){      # Compute the number of classes for a histogram   break.func <- break.func [1]   if(is.null(breaks)){     x.breaks <- switch(break.func,                        Sturges = nclass.Sturges(ten),                        scott = nclass.scott(x),                        FD = nclass.FD(x))     y.breaks <- switch(interruption.func,                        Sturges = nclass.Sturges(y),                        scott = nclass.scott(y),                        FD = nclass.FD(y))   } else 10.breaks <- y.breaks <- breaks      # Cut x and y variables in bins for counting   x.bin <- seq(min(ten), max(x), length.out = x.breaks)   y.bin <- seq(min(y), max(y), length.out = y.breaks)   xy <- table(cut(x, 10.bin), cutting(y, y.bin))   z <- xy      xmid <- 0.5*(x.bin[-1] + x.bin[-length(10.bin)])   ymid <- 0.v*(y.bin[-1] + y.bin[-length(y.bin)])      oldmar <- par("mar")   par (mar = par("mar") + c(0, 0, 0, 2))   hist3D(x = xmid, y = ymid, z = xy, ...,     zlim = c(-max(z)/2, max(z)), zlab = "counts", bty= "m",      phi = phi, theta = theta,     shade = 0.two, col = col, border = "black",     d = ane, ticktype = "detailed")       scatter3D(10, y,     z = rep(-max(z)/two, length.out = length(10)),     colvar = colvar, col = gg.col(100),     add = TRUE, pch = eighteen, clab = clab,     colkey = listing(length = 0.v, width = 0.5,        dist = 0.05, cex.axis = 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: 2nd scatter plot

Create some data:

            # 10, y coordinates ready.seed(1234) x  <- sort(rnorm(10))  y  <- runif(10) # Variable for coloring points col.5 <- sqrt(x^ii + y^two)                      

Bones 2D scatter plot:

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

plot3D - R software and data visualization


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

2D scatter plot with confidence interval:

            # Confidence interval for x variable merely CI <- list() CI$x <- matrix(nrow = length(x), information = c(rep(0.25, two*length(x)))) scatter2D(x, y, colvar = col.v, pch = 16, bty ="due north", 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), data = c(rep(0.05, 2*length(y)))) CI$col <- "black" scatter2D(x, y, colvar = col.5, pch = xvi,  bty ="n", cex = 1.5,           CI = CI, type ="b")          

plot3D - R software and data visualization

            CI$y[c(2,4,8,x), ] <- NA  # Some points have no CI CI$x[c(2,four,8,10), ] <- NA  # Some points have no CI CI$alen <- 0.02            # increase arrow head scatter2D(x, y, colvar = col.v, pch = xvi,  bty ="northward", cex = 1.v,           CI = CI, type ="b")          

plot3D - R software and data visualization

text2D

            # Only text with(USArrests, text2D(x = Murder, y = Attack + five, colvar = Rape,       xlab = "Murder", ylab = "Assault", clab = "Rape",       primary = "USA arrests", labels = rownames(USArrests), cex = 0.6,       adj = 0.5, font = 2))          

plot3D - R software and data visualization

            # text with point  with(USArrests, text2D(x = Murder, y = Assault + five, colvar = Rape,       xlab = "Murder", ylab = "Assail", clab = "Rape",       principal = "USA arrests", labels = rownames(USArrests), cex = 0.6,       adj = 0.5, font = two))  with(USArrests, scatter2D(x = Murder, y = Assault, colvar = Rape,       pch = 16, add = True, colkey = False))          

plot3D - R software and data visualization

Other functions

It's besides possible to draw arrows, segments and rectangles in a 3D or second plot using the functions below:

            arrows3D(x0, y0, z0, x1, y1, z1, ..., colvar = Nada,          col = NULL, blazon = "triangle", add = Simulated) segments3D(x0, y0, z0, x1, y1, z1, ..., colvar = Zero,            col = Naught, add together = "Imitation") rect3D(x0, y0, y0, x1, y1, z1, ..., colvar = NULL,        col = NULL, add = FALSE) arrows2D(x0, y0, z0, x1, y1, z1, ..., colvar = Null,          col = Zippo, blazon = "triangle", add together = FALSE) segments2D(x0, y0, z0, x1, y1, z1, ..., colvar = Zilch,            col = Nothing, add together = "Simulated") rect2D(x0, y0, y0, x1, y1, z1, ..., colvar = Nil,        col = Nada, add = FALSE)          

  • x0, y0, z0: coordinates of points from which to draw
  • x1, y1, z1: coordinates of points to which to draw. For arrows3D and segments3D, at least i must be supplied. For rect3D exactly one must be NULL.
  • colvar: The variable used for coloring.
  • col: colour palette to be used for coloring. Default is cerise-xanthous-blueish color scheme.
  • add: Logical. If TRUE, so the arrows, segments, … will be added to the current plot. If Faux a new plot is started.

Gear up the data: we want to plot four arrows starting from the point of coordinates c(x0, y0, z0) and ending 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^two, col = cols,          lwd = two, d = 3, clab = c("Quality", "score"),           master = "Arrows 3D", bty ="g", ticktype = "detailed") # Add starting signal of pointer points3D(x0, y0, z0, add = TRUE, col="darkred",            colkey = Fake, pch = nineteen, cex = one) # Add labels to the arrows text3D(x1, y1, z1, c("Sepal.L", "Sepal.Westward", "Petal.L", "Petal.Due west"),        colvar = x1^2, col = cols, add together=TRUE, colkey = FALSE)          

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(-i, 1), ylim = c(-1, 1)) # Add together vertical and horizontal lines at c(0,0) abline(h =0, v = 0, lty = ii) # Add starting indicate of arrow points2D(x0, y0, add = TRUE, col="darkred",            colkey = FALSE, pch = 19, cex = 1) # Add labels to the arrows text2D(x1, y1, c("Sepal.L", "Sepal.Due west", "Petal.L", "Petal.W"),        colvar = x1^2, col = cols, add=True, colkey = False)          

plot3D - R software and data visualization

Note that, segments3D() and segments2D() are very like to arrows3D() and arrows2D() and yous can play with them besides.

3D rectangle: the R lawmaking below creates a rectangle with a transparent fill colour (alpha = 0.five)

            rect3D(x0 = 0, y0 = 0.v, z0 = 0, x1 = 1, z1 = five,         ylim = c(0, 1), bty = "g", facets = Truthful,         edge = "red", col ="#7570B3", alpha=0.5,        lwd = 2, phi = twenty)          

plot3D - R software and data visualization

In the R lawmaking above, facets = Fake, volition remove the rectangle fill color.

2d rectangle:

            rect2D(x0 = runif(3), y0 = runif(3),         x1 = runif(3), y1 = runif(3), colvar = 1:iii,         alpha = 0.4, lwd = ii, chief = "rect2D")          

plot3D - R software and data visualization

Interactive plot

To depict an interactive 3D plot the packet plot3Drgl can be used.

The package plot3Drgl allows to plot the graph generated with plot3D in openGL, every bit fabricated available by packet rgl.

The simplest way is to exercise as follow:

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

The packet rgl allows to interactively rotate, zoom the graphs. Nevertheless it'southward not yet possible to plot a colorkey

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

RGL movie 3d


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

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

  • …: any arguments for par3d, open3d or material3d in rgl package.

This page has been seen 457639 times

smiththendre1958.blogspot.com

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

0 Response to "how to draw 3d graph on graph paper"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel