[R] grouping in scatterplot3d

Rishabh Gupta rg117 at ohm.york.ac.uk
Thu Jul 4 18:28:46 CEST 2002


Hi,
    Thanks very much for you reply.
My data has 3 independent variable and the fourth one is the group variable. I adapted the code that you gave me in the following
way (d is my original data structure, contains the grouping variables and independent variables)

G <- d$groupvariable
x <- t(d[11])
y <- t(d[12])
z <- t(d[13])

s3d <- scatterplot3d(x, y, z, type = "n")

for (g in unique(G))
{

    bxp.stx <- boxplot.stats(x[G==g])
    bxp.sty <- boxplot.stats(y[G==g])
    bxp.stz <- boxplot.stats(z[G==g])

    # whiskers
    lines(s3d$xyz.convert(bxp.stx$stats[c(3, 3)], bxp.sty$stats[c(3, 3)], bxp.stz$stats[c(1, 5)]))
    lines(s3d$xyz.convert(bxp.stx$stats[c(3, 3)], bxp.sty$stats[c(1, 5)], bxp.stz$stats[c(3, 3)]))
    lines(s3d$xyz.convert(bxp.stx$stats[c(1, 5)], bxp.sty$stats[c(3, 3)], bxp.stz$stats[c(3, 3)]))

    # box
    lines(s3d$xyz.convert(bxp.stx$stats[c(3, 3)], bxp.sty$stats[c(3, 3)], bxp.stz$stats[c(2, 4)]), lwd = 3)
    lines(s3d$xyz.convert(bxp.stx$stats[c(3, 3)], bxp.sty$stats[c(2, 4)], bxp.stz$stats[c(3, 3)]), lwd = 3)
    lines(s3d$xyz.convert(bxp.stx$stats[c(2, 4)], bxp.sty$stats[c(3, 3)], bxp.stz$stats[c(3, 3)]), lwd = 3)

    # median
    s3d$points3d(bxp.stx$stats[3], bxp.sty$stats[3], bxp.stz$stats[3], pch = 18, col = "red")
}


Just a thought. I understand that you wrote the scatterplot3d package. May be you could add a 3dboxplot function to that package
(something like the one above but better coding).
Many thanks for your help.

Rishabh

----- Original Message -----
From: "Uwe Ligges" <ligges at statistik.uni-dortmund.de>
To: "Rishabh Gupta" <rg117 at ohm.york.ac.uk>
Cc: <r-help at stat.math.ethz.ch>
Sent: Wednesday, July 03, 2002 10:02 PM
Subject: Re: [R] grouping in scatterplot3d


| Rishabh Gupta wrote:
| >
| > Hi,
| >     Thanks very much for your reply.
| > I think what I was hoping for was a 3d version of boxplot.
| > Box plot will give me a median, the quartiles and the upper
| > and lower range for each group. If there is a function that
| > would give me the same information but for 3d plots, that is
| > really what I was hoping for.
|
| Not really easy, but a quick hack can be done along the following lines
| with scatterplot3d (in CRAN package of the same name):
|
|  # data:
|  z <- rnorm(100)
|  x <- sample(1:5, size = 100, replace = TRUE) # categorial
|  y <- sample(1:5, size = 100, replace = TRUE) # categorial
|
|  # set up the plot without drawing, and save the returned functions
|  # (see ?scatterplot3d section "Values"):
|  s3d <- scatterplot3d(x, y, z, type = "n")
|
|  # Just a double loop, not speed issues if looping for such a plot -
|  # or plot cannot show anything:
|  for(i in unique(x)){
|    for(j in unique(y)){
|      # calculate boxplot stats for this each plot group:
|      bxp.st <- boxplot.stats(z[x==i & y==j])
|      l <- length(bxp.st$out)
|      # plot outliers:
|      if(length(bxp.st$out) > 0)
|        s3d$points3d(rep(i, l), rep(j, l), bxp.st$out)
|      # calculate "whiskers" and plot them:
|      lines(s3d$xyz.convert(c(i, i), c(j, j), bxp.st$stats[c(1, 5)]))
|      # calculate "box" and plot it:
|      lines(s3d$xyz.convert(c(i, i), c(j, j), bxp.st$stats[c(2, 4)]),
|        lwd = 3)
|      # plot the median:
|      s3d$points3d(i, j, bxp.st$stats[3], pch = 18, col = "red")
|    }
|  }
|
|
| Uwe Ligges
| -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
| r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
| Send "info", "help", or "[un]subscribe"
| (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
| _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
|

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list