3d scatter plot using R

January 6, 2010
By

(This article was first published on stattler.com - R, and kindly contributed to R-bloggers)

The other day I saw a three dimensional scatterplot in Montgomery’s Regression book. I wanted to redraw the graph using the provided data. A simple google search revealed that there is a package called scatterplot3d. The scatterplot3d() can be used to draw a 3-dimensional scatter plot. Here is what the steps are:

Download and install the package from your nearest CRAN.
Load the package using the command library(scatterplot3d)

Use the attached file to run the following code in R

d1<-read.table("65-555-reg.txt", header=T)
d2<-data.frame(time=c(d1[,1]), cases=c(d1[,2]), distance=c(d1[,3]))
attach(d2)
scatterplot3d(cases, distance, time, angle=20, col.axis="blue",
col.grid="lightblue", main="Three-dimensional scatterplot", 
pch=21, box=F, cex.symbols=2)
detach(d2)

RESULT
3dscatterplot.jpeg

DATA
Data: Copy and paste in a file and save it as 65-555-reg.txt

time	 cases	distance
16.68	7	560
11.5	3	220
12.03	3	340
14.88	4	80
13.75	6	150
18.11	7	330
 8	2	110
17.83	7	210
79.24	30	1460
21.5	5	605
40.33	16	688
21	10	215
13.5	4	255
19.75	6	462
24	9	448
29	10	776
15.35	6	200
19	7	132
9.5	3	36
35.1	17	770
17.9	10	140
52.32	26	810
18.75	9	450
19.83	8	635
10.75	4	150



Category: 

To leave a comment for the author, please follow the link and comment on their blog: stattler.com - R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training

datasociety

http://www.eoda.de





ODSC

ODSC

CRC R books series





Six Sigma Online Training









Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)