三維散點圖是指在x,y,z三維坐標上繪製散點圖。我們介紹用scatterplot3d包和rgl包繪三維散點圖。
scatterplot3d
library(scatterplot3d)
s3d<-scatterplot3d(iris[,1:3],color=as.integer(iris$Species), pch=16,type="p",
grid=FALSE,
angle=30)
#標註文字
text(s3d$xyz.convert(iris[,1:3]),labels=iris$Species,cex= 0.6)
#改變類型加投影線
s3d<-scatterplot3d(iris[,1:3],color=as.integer(iris$Species), pch=16,type="h",
grid=FALSE,
angle=30)
2. rgl包
library(rgl)
plot3d(iris[,1:3],col=as.integer(iris$Species))
將會打開一個窗口,可以轉動圖像
下一講:Wilkinson點圖和Cleveland點圖的繪製