Created
August 26, 2013 05:55
-
-
Save srgist/6338408 to your computer and use it in GitHub Desktop.
Venn Dia2 -- for stagewise -- diabetes progression
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
circle <- function(x, y, r, ...) { | |
ang <- seq(0, 2*pi, length = 100) | |
xx <- x + r * cos(ang) | |
yy <- y + r * sin(ang) | |
polygon(xx, yy, ...) | |
} | |
venndia2 <- function(A, B, C, label,getdata=FALSE, ...){ | |
cMissing <- missing(C) | |
if(cMissing){ C <- c() } | |
unionAB <- union(A, B) | |
unionAC <- union(A, C) | |
unionBC <- union(B, C) | |
uniqueA <- setdiff(A, unionBC) | |
uniqueB <- setdiff(B, unionAC) | |
uniqueC <- setdiff(C, unionAB) | |
intersAB <- setdiff(intersect(A, B), C) | |
intersAC <- setdiff(intersect(A, C), B) | |
intersBC <- setdiff(intersect(B, C), A) | |
intersABC <- intersect(intersect(A, B), intersect(B, C)) | |
nA <- length(uniqueA) | |
nB <- length(uniqueB) | |
nC <- length(uniqueC) | |
nAB <- length(intersAB) | |
nAC <- length(intersAC) | |
nBC <- length(intersBC) | |
nABC <- length(intersABC) | |
par(mar=c(2, 2, 0, 0)) | |
plot(-10, -10, ylim=c(0, 9), xlim=c(0, 9), axes=FALSE, ...) | |
circle(x=4.5, y=4.5, r=3, col=rgb(1,0,.8,.5), border=NA) | |
circle(x=4.5, y=3.5, r=2, col=rgb(0,.5,.1,.5), border=NA) | |
circle(x=4.5, y=2.5, r=1, col=rgb(0,.2,1,.5), border=NA) | |
text( x=c(1,1,1), y=c(6.5, 4.5 , 2.5), label, cex=1, col="blue" ) | |
text( | |
x=c(4.5, 4.5, 4.5), | |
y=c(6.5, 4.5 , 2.5), | |
c(nA, nAB, nABC), | |
cex=1, col="yellow" | |
) | |
if(getdata){ | |
list(A=uniqueA, B=uniqueB, C=uniqueC, | |
AB=intersAB , AC=intersAC , BC=intersBC , | |
ABC=intersABC | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment