Adding horizontal lines to 3d scatterplot

45 views
Skip to first unread message

Christoph Ruehlemann

unread,
Dec 10, 2016, 7:25:17 AM12/10/16
to corplin...@googlegroups.com
Dear all,

This code draws a regular 4x4x4 cube and marks all 64 intersections connecting them vertically -- but not horizontally!:

x <- c(rep(1:4,16))
y <- c(rep(c(rep(1,4),rep(2,4),rep(3,4),rep(4,4)),4))
z <- c(rep(1,16),rep(2,16),rep(3,16),rep(4,16))
dat<-as.data.frame(cbind(x, y, z))
scatterplot3d(dat, type="h", lwd=1, axis=T,
              lty.grid="dashed", color="blue",
              box=T, label.tick.marks=F,
              ylab="y", xlab="x", zlab="z",
              tick.marks=F, pch=21)


I'd be grateful for pointers as to how to draw additonal *horizontal* lines connecting the points!

Best
Chris

Stefan Th. Gries

unread,
Dec 10, 2016, 3:24:21 PM12/10/16
to CorpLing with R
See <https://www.jstatsoft.org/index.php/jss/article/view/v008i11/JSSs3d.pdf>, Section 3. That means for your case:

library(scatterplot3d)
dat <- data.frame(x=c(rep(1:4,16)),
                  y=c(rep(c(rep(1,4),rep(2,4),rep(3,4),rep(4,4)),4)),
                  z=c(rep(1,16),rep(2,16),rep(3,16),rep(4,16)))
qwe <- scatterplot3d(dat, type="h", color="blue")
qwe$points3d(c(1.5,1.5,1.5), c(2.5,2.5,2.5),type="b",col="red",cex=3,pch=16)

Best,
STG
--
Stefan Th. Gries
----------------------------------
Univ. of California, Santa Barbara
http://tinyurl.com/stgries
----------------------------------

Christoph Ruehlemann

unread,
Dec 11, 2016, 8:09:51 AM12/11/16
to corplin...@googlegroups.com
That was helpful. Thanks a lot!
Chris

--
You received this message because you are subscribed to the Google Groups "CorpLing with R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to corpling-with-r+unsubscribe@googlegroups.com.
To post to this group, send email to corpling-with-r@googlegroups.com.
Visit this group at https://groups.google.com/group/corpling-with-r.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages