Created
December 14, 2014 22:50
-
-
Save cmtucker/c591e868c76de1ac81e6 to your computer and use it in GitHub Desktop.
snowflakeCode
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
if( ! require( "circlize" , character.only = TRUE ) ){ | |
# If package was not able to be loaded then re-install | |
install.packages( "circlize" , dependencies = TRUE ) | |
# Load package after installing | |
require( "circlize" , character.only = TRUE ) | |
} | |
rm(list=ls()) | |
####Start | |
dev.new <- function(width = 5, height = 5){ | |
platform <- sessionInfo()$platform | |
if (grepl("linux",platform)) { | |
x11(width=width, height=height) | |
}else{ | |
if (grepl("pc",platform)) { | |
windows(width=width, height=height) | |
}else{ | |
if (grepl("w32",platform)) { | |
windows(width=width, height=height) | |
}else{ | |
if (grepl("apple", platform)){ | |
quartz(width=width, height=height)} }}}} | |
dev.new(7, 7) | |
par(mfrow=c(2,2),mar=c(1,1,1,1),bg=sample(c("#FFFAFA","#F8FFFF","#F5FFF9"),1)) | |
for(z in 1:4){ | |
##Random variables | |
p=sample(c(0,2),1) | |
s1 <- sample(c(4,6,8),1) | |
t <- s1*sample(6:8,1) | |
totals <- rep(80, t) | |
arms <- sample(c(1,2,2,3,3,4),1) | |
start_ang <- as.numeric(sample(seq(from=0,to=360), 1)) | |
#cols | |
flakecols <- c("#B0C4DE", "#CDC5BF", "#FFF9B9", "#E6E6FA", "#CCE5E5", "#F9E4B9", "#FFE1DE", "#FFFFF0", "#6a7374") | |
cols <- sample(flakecols, 3) | |
#data | |
df1 <- data.frame(order=1:t, region=1:t, | |
rcol = rep(cols,t)[t], | |
lcol = "#4c4c4c", | |
stringsAsFactors=FALSE) | |
df1$xmin <- 0 | |
df1$xmax <- totals | |
##Plot | |
circos.clear() | |
circos.par(cell.padding=c(0,0,0,0), track.margin=c(0.0,0.0), start.degree=start_ang, gap.degree=sample(c(0,5),1)) | |
circos.initialize(factors = df1$region, xlim = cbind(df1$xmin, df1$xmax)) | |
circos.trackPlotRegion(ylim = c(0, 1), factors = df1$region, track.height=0.01, | |
panel.fun = function(x, y) { | |
name = get.cell.meta.data("sector.index") | |
i = get.cell.meta.data("sector.numeric.index") | |
xlim = get.cell.meta.data("xlim") | |
ylim = get.cell.meta.data("ylim") | |
circos.rect(xleft=xlim[1], ybottom=ylim[1], xright=xlim[2], ytop=ylim[2], col = df1$rcol[i], lwd=0.05) | |
}) | |
index1 <- c(0,0,0,0,0,seq(1:t),0,0,0,0,0) | |
index2 <- c(t-4,t-3,t-2,t-1,t,seq(1:t),1,2,3,4,5) | |
for(m in 0:(s1-1)){ | |
aa <- m*t/s1+1 | |
bb <- ifelse((m*t/s1+1+t/2)>t,(m*t/s1+1+t/2)-t,(m*t/s1+1+t/2)) | |
circos.link(sector.index1=df1$region[aa], point1=c(25,27), sector.index2=df1$region[bb], point2=c(4, 5), col = cols[1], border="#4c4c4c", lwd=0.25, w=-0.05) | |
circos.link(sector.index1=df1$region[aa], point1=c(4, 5), sector.index2=df1$region[bb], point2=c(25, 27), col = cols[1], border="#4c4c4c", lwd=0.25, w=-0.05) | |
circos.link(sector.index1=df1$region[aa], point1=c(10,20), sector.index2=df1$region[aa], point2=c(10,20), col = cols[1], border="#4c4c4c", h=-0.25, lwd=0.25) | |
circos.link(sector.index1=df1$region[bb], point1=c(10,20), sector.index2=df1$region[bb], point2=c(10,20), col = cols[1], border="#4c4c4c", h=-0.25, lwd=0.25) | |
for(i in 1:arms){ | |
cc <- sample(cols,1) | |
ht=runif(1, min=0.15, max=1) | |
circos.link(sector.index1=df1$region[index2[which(index1==aa)+i]], point1=c(8, 17), sector.index2=df1$region[index2[which(index1==aa)-i]], point2=c(8,17), col = cc, border="#4c4c4c", lwd=0.15, h=ht, w=1) | |
circos.link(sector.index1=df1$region[index2[which(index1==bb)+i]], point1=c(8, 17), sector.index2=df1$region[index2[which(index1==bb)-i]], point2=c(8, 17), col = cc, border="#4c4c4c", lwd=0.15, h=ht, w=1) | |
} | |
} | |
} | |
title(main="Happy Holidays 2014", outer=TRUE, cex.main=2.5, col.main="#8B0000", family="serif",sub="from the EEB & Flow",cex.sub=2,col.sub="#8B0000",line=-2) | |
## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment