search for: factorlevel

Displaying 2 results from an estimated 2 matches for "factorlevel".

2012 Mar 15
2
Ggplot barchart drops factor levels: how to show them with zero counts?
...barchart with ggplot it drops the levels of the factor for which no counts are available. For example: library(ggplot) mtcars$cyl<-factor(mtcars$cyl) ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar() levels(mtcars[!mtcars$cyl==4,]) This shows my problem. Because no counts are available for factorlevel '4', the label 4 dissapears from the plot. However, I would still like it to show up, but without a bar (zero observations). I would like to use this for the presentation of data with a Likert-like scale. Thanks in advance! Bart -- View this message in context: http://r.789695.n4.nabble....
2011 Mar 27
1
run function on subsets of matrix
...gh different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) Now, the problem is that if a value in 'fac' only occurs once, the 'apply' function will complain. But I think, this can also be written more cleverly using some R style construct using factorlevels. Thanks