GG3D | ggplot extends

GG3D | ggplot extends

1. 安装

install.packages('devtools')
devtools::install_github("AckerDWM/gg3D")

Quick Start

看图

library(gg3D)
library(ggplot2)
theta=1 #方位角的度数
phi=50 # 渐近线
ggplot(iris, aes(x=Petal.Width, y=Sepal.Width, z=Petal.Length, color=Species)) +
axes_3D(theta=theta, phi=phi) + stat_3D(theta=theta, phi=phi) +
axis_labs_3D(theta=theta, phi=phi, size=3, hjust=c(1,1,1.2,1.2,1.2,1.2), vjust=c(-.5,-.5,-.2,-.2,1.2,1.2)) +
labs_3D(theta=theta, phi=phi, hjust=c(1,0,0), vjust=c(1.5,1,-.2),labs=c("Petal width", "Sepal width", "Petal length")) +theme_void()

theta & phi的关系

## 查看theta
for(i in c(0:100)){
theta=i #方位角的度数
phi=1 # 渐近线
p <- ggplot(iris, aes(x=Petal.Width, y=Sepal.Width, z=Petal.Length, color=Species)) +
axes_3D(theta=theta, phi=phi) + stat_3D(theta=theta, phi=phi) +
axis_labs_3D(theta=theta, phi=phi, size=3, hjust=c(1,1,1.2,1.2,1.2,1.2), vjust=c(-.5,-.5,-.2,-.2,1.2,1.2)) +
labs_3D(theta=theta, phi=phi, hjust=c(1,0,0), vjust=c(1.5,1,-.2),labs=c("Petal width", "Sepal width", "Petal length")) +theme_void()+
labs(title =paste("theta=",i))
print(p)
##ggsave(paste(i,'.png',sep=""))
}
##convert $(ls *.png| sort -n) theta.gif

##查看phi
for(i in c(0:100)){
theta=1 #方位角的度数
phi=i # 渐近线
p <- ggplot(iris, aes(x=Petal.Width, y=Sepal.Width, z=Petal.Length, color=Species)) +
axes_3D(theta=theta, phi=phi) + stat_3D(theta=theta, phi=phi) +
axis_labs_3D(theta=theta, phi=phi, size=3, hjust=c(1,1,1.2,1.2,1.2,1.2), vjust=c(-.5,-.5,-.2,-.2,1.2,1.2)) +
labs_3D(theta=theta, phi=phi, hjust=c(1,0,0), vjust=c(1.5,1,-.2),labs=c("Petal width", "Sepal width", "Petal length")) +theme_void()+
labs(title =paste("phi=",i))
print(p)
##ggsave(paste(i,'.png',sep=""))
}
##convert $(ls *.png| sort -n) phi.gif

Theta Phi
NuhKsS.gif NuhMqg.gif

More

Author

Karobben

Posted on

2020-06-19

Updated on

2023-06-06

Licensed under

Comments