[分享] 2D scatter plot, 座標旋轉

作者: gsuper (Logit(odds))   2015-06-01 16:42:48
[旋轉角度]
a <- cbind(c(1,0,-1,0,0.5),c(0,1,0,-1,0.5))
b <- a
degree <- 60
b[,1] <- a[,1]*cos(2*pi/360*degree) - a[,2]*sin(2*pi/360*degree)
b[,2] <- a[,1]*sin(2*pi/360*degree) + a[,2]*cos(2*pi/360*degree)
COLOR <- c("red","orange","blue","purple","black")
par(mfrow=c(1,2))
plot(a,xlim=c(-2,2),ylim=c(-2,2),lty=1,col=COLOR,pch=19)
plot(b,xlim=c(-2,2),ylim=c(-2,2),lty=1,col=COLOR,pch=19)
#############################################
[鏡像]
b <- a ; b[,1] <- -a[,1] # 左右
b <- a ; b[,2] <- -a[,2] # 上下
#############################################
[重心計算]
group <- c(1,1,2,2,2)
Cen1 <- colMeans(a[group==1,])
Cen2 <- colMeans(a[group==2,])
#############################################
[夾角計算]
#############################################
[電子雲]
plot(B1[,1],B1[,2],xlim=XLIMB1,ylim=YLIMB1,pch=19,
main="多維標度法 (PCoA)",col=gsub("..$","03",Color),
xaxt='n',yaxt='n',xlab="",ylab="",cex=30,cex.main=2)
points(B1[,1],B1[,2],pch=19,col=gsub("..$","05",Color),cex=20)
points(B1[,1],B1[,2],pch=19,col=gsub("..$","07",Color),cex=10)
points(B1[,1],B1[,2],pch=19,col=gsub("..$","08",Color),cex=5)
作者: celestialgod (天)   2015-06-01 17:10:00
推薦你可以用rgl畫,可以自由旋轉....我誤會你的圖了...你可以改成用Givens rotationrot_mat = function(degree) cos(degree*2*pi/360)+c(0,sin(degree*2*pi/36)*c(-1,1),0)b = a %*% rot_mat(degree)
作者: gsuper (Logit(odds))   2015-06-01 17:57:00
行列式有點苦手
作者: celestialgod (天)   2015-06-08 11:00:00
不太懂你的電子雲要做什麼?很多變數都沒有跑不出來Q____Q

Links booklink

Contact Us: admin [ a t ] ucptt.com