内容简介:在《我们首先定义一个转换函数:然后我们使用一个3D兔子的坐标来测试一下,当然一般画3D的程序都支持你用鼠标交互,比如旋转角度什么的,但我们用
在《 扪心自问,meme几何? 》一文中,我画了一只兔子,今天给大家演示一下画一只3D版本的兔子,我们知道 ggplot2 不支持3D,只能画2D的图,但3D其实只是视觉上的,显示在你屏幕上的,同样只是2D。所以我们要做的,就是把3D的坐标转换成2D,然后画出2D的图片来,而这2D看上去有3D的效果。
我们首先定义一个转换函数:
trans_3d_2d <- function(data, theta=135, phi=60) {
pmat <- plot3D::perspbox(z=diag(2), plot=F, theta=theta, phi=phi)
data <- as.data.frame(data)
XY <- plot3D::trans3D(
x = data$x,
y = data$y,
z = data$z,
pmat = pmat) %>%
data.frame()
data$x <- XY$x
data$y <- XY$y
return(data[, c('x', 'y')])
}
然后我们使用一个3D兔子的坐标来测试一下,当然一般画3D的程序都支持你用鼠标交互,比如旋转角度什么的,但我们用 ggplot2 就不可以,我们能做到的,就是在调用上面的转换函数时,指定不同的角度而已。
require(onion) data(bunny) d <- trans_3d_2d(bunny) require(ggplot2) ggplot(d, aes(x, y, color=x)) + geom_point(alpha=.2) + coord_flip() + theme(legend.position="none") + scale_y_reverse()
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
New Dark Age
James Bridle / Verso Books / 2018-7-17 / GBP 16.99
As the world around us increases in technological complexity, our understanding of it diminishes. Underlying this trend is a single idea: the belief that our existence is understandable through comput......一起来看看 《New Dark Age》 这本书的介绍吧!