Wednesday, April 10, 2013

RG#50: beeswarm box violin plot


# data
set.seed(1234)
bimodal <- c(rnorm(250, -2, 0.6), rnorm(250, 2, 0.6))
uniform <- runif(500, -4, 4)
normal <- rnorm(500, 0, 1.5)
dataf <- data.frame (group = rep(c("bimodal","uniform", "normal"), each = 500), xv = c(bimodal, uniform, normal), cg = rep( c("A","B"), 750))




require(beeswarm)
beeswarm(xv ~ group, data = dataf,method = 'swarm',
pch = 16, pwcol = as.numeric(cg),
xlab = '', ylab = 'xv', labels = c('bimodal', 'uniform', 'normal'))

 

# center 
beeswarm(xv ~ group, data = dataf,
        method = 'center',
        pch = 16, pwcol = as.numeric(cg),
        xlab = '', ylab = 'xv',
        labels = c('bimodal''uniform', 'normal'))
# hexagon 
beeswarm(xv ~ group, data = dataf,
        method = 'hex',
        pch = 16, pwcol = as.numeric(cg),
        xlab = '', ylab = 'xv',
        labels = c('bimodal''uniform', 'normal'))
# square
dataf$col <- as.numeric(dataf$cg)
dataf$col[dataf$col ==1] = "green4"
dataf$col[dataf$col ==2] = "purple"
beeswarm(xv ~ group, data = dataf,
       method = 'square',
        pch = 16, pwcol = col,
        xlab = '', ylab = 'xv',
        labels = c('bimodal''uniform', 'normal'))





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.