On 2011-01-28 06:09, Uwe Ligges wrote:


On 28.01.2011 14:21, pdb wrote:

In a boxplot - how can I prevent groups where the number of cases is less
than a set threshold from being plotted.

set.seed(42)
   DF<- data.frame(type=sample(LETTERS[1:5], 100, replace=TRUE),
cost=rnorm(100))
   count<- boxplot(cost ~ type, data=DF, plot = 0)
   count$n

## how to only include plots where count$n>   18
   boxplot(cost ~ type, data=DF)

Thanks in advance for any solutions.

set.seed(42)
DF<- data.frame(type = sample(LETTERS[1:5], 100, replace=TRUE),
                   cost = rnorm(100))
count<- boxplot(cost ~ type, data=DF, plot = 0)
for(i in c(1,3)) count[[i]]<- count[[i]][,count$n>  18]
for(i in c(6,2)) count[[i]]<- count[[i]][count$n>  18]
bxp(count)

Uwe Ligges


Here's another way:

 count <- c(table(DF$type))
 DF1 <- subset(DF, type %in% levels(type)[count > 18])
 boxplot(cost ~ type, DF1)
 boxplot(cost ~ type, droplevels(DF1))

Peter Ehlers

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to