Despite using ggplot a few times already, I am really struggling to make any headway with this problem. I guess it will be easiest to explain what I want to do without my abominable attempt at using ggplot, The following is quite ugly too, but it's the best I can manage at the moment :(
require(mice)
impute <- mice(nhanes, seed = 101)
counts <- table(nhanes$hyp)
barplot(counts, main="hyp", xlab="observed")
x11()
counts <- table(complete(impute,1)$hyp)
barplot(counts, main="hyp", xlab="Imputation 1")
x11()
counts <- table(complete(impute,2)$hyp)
barplot(counts, main="hyp", xlab="Imputation 2")
x11()
counts <- table(complete(impute,3)$hyp)
barplot(counts, main="hyp", xlab="Imputation 3")
x11()
counts <- table(complete(impute,4)$hyp)
barplot(counts, main="hyp", xlab="Imputation 4")
x11()
counts <- table(complete(impute,5)$hyp)
barplot(counts, main="hyp", xlab="Imputation 5")
I would like to create a nice looking grid of plots showing these kind of barplots in ggplot - for example, 1 row of 6, all with the same scale on the y axis so that they can be easily compared.
I think I should use ldt <-complete(impute,"long", include=TRUE)
and then melt(ldt, c(".imp",".id","hyp"))
but I just can't work out how to call ggplot after that :(
Please note that I have many different variables in my real data, and this only applies to the categorical variables. I was thinking I could make make a function and then run that using sapply
, but only on the categorical columns ? But I don't have much idea of how to do that !