Created
October 7, 2014 04:50
-
-
Save kohske/cddbd2ac75d96a59cf11 to your computer and use it in GitHub Desktop.
pie3d -- interactive 3d pie chart by R and rgl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgl) | |
pie3d <- function(x, depth = 0.2, webgl = TRUE) { | |
x = cumsum(x)/sum(x) | |
ps = embed(c(0, 2*pi*x), 2) | |
for (i in 1:nrow(ps)) { | |
p = seq(ps[i, 2], ps[i, 1], by = 2*pi/360) | |
rgl.triangles(rep(c(t(cbind(embed(sin(p), 2), 0))), 2), | |
rep(c(t(cbind(embed(cos(p), 2), 0))), 2), | |
rep(c(-depth, depth), each = (length(p)-1)*3), | |
col = i) | |
rgl.quads(sin(c(t(cbind(embed(p, 2), embed(p, 2))[, c(1, 2, 4, 3)]))), | |
cos(c(t(cbind(embed(p, 2), embed(p, 2))[, c(1, 2, 4, 3)]))), | |
rep(c(-depth, depth), each = 2, length = (length(p)-1)*4), | |
col = i) | |
} | |
if(webgl) { | |
browseURL(writeWebGL(".")) | |
} | |
} | |
pie3d(1:5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment