3d scatter plot using R
[This article was first published on stattler.com - R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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
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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.