ggmice
ggmice copied to clipboard
Wrapper function for density plots
Hey, Hanne! I created a ggplot2
version of the mice
density diagnostic plots for a paper I am writing. When I thought about using ggmice
I had already dedicated quite a bit of work to it 🙈. Out of curiosity, I tried to implement my take on these gg density plots in your package. I am not sure whether my plot_density()
function fits well with your vision for ggmice
, but I thought it might be worth sharing with you and seeing what you think about it. If you want to check it out, here is a code example inspired by your old_friends.Rmd
vignette:
# load packages
library(ggmice)
library(mice)
library(ggplot2)
# load incomplete dataset from mice
dat <- boys
# generate imputations
imp <- mice(dat, method = "pmm", printFlag = FALSE)
# original plot
mice::densityplot(imp, ~hgt)
# Can make the same plot
plot_density(data = imp, vrb = "hgt")
# Can be broken down by panels
plot_density(data = imp, vrb = "hgt", panels = TRUE)
# Can plot arbitrary variables
plot_density(data = imp, vrb = c("wgt", "bmi", "phb"), panels = FALSE)
# Can plot arbitrary variables in panels
plot_density(data = imp, vrb = c("wgt", "bmi", "phb"), panels = TRUE)
# Can plot all variables
plot_density(data = imp)