r - Boxplots: avoid blank space due to non-existing interactions -


i'm plotting boxplot of y interactions between 2 variables x1 , x2. problem levels there no data, boxplot still shows blank space boxplot.

how can avoid blank space? in reality have many more 2 factor levels. also, avoid ggplot2-based solutions.

example:

> set.seed(0) > t <- data.frame(y =rnorm(60),                   x1 = rep(c("a","a","b"), each=20),                   x2 = rep(c("c","d","d"), each=20)) > boxplot(y~x1+x2, t) > points(aggregate(y~x1+x2, t, mean)$y, col="red") 

the points function plot means not know missing interaction b.c, points don't correspond groups:

enter image description here

i work out output of boxplot(y~x1+x2, t, plot=f), don't know how plot modified object.

> b <- boxplot(y~x1+x2, t, plot=f) > <- complete.cases(t(b$stats)) > b$stats <- b$stats[,i] > b$n <- b$n[i] > b$conf <- b$conf[,i] > b$names <- b$names[i] 

you can create 1 variable containing interaction interaction. can drop unused levels droplevels:

boxplot(y ~ droplevels(interaction(x1, x2)), t)  points(aggregate(y ~ droplevels(interaction(x1, x2)), t, mean)$y, col="red") 

enter image description here


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -