ggmice icon indicating copy to clipboard operation
ggmice copied to clipboard

Wrapper function for density plots

Open EdoardoCostantini opened this issue 1 year ago • 1 comments

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)

plot

# Can make the same plot
plot_density(data = imp, vrb = "hgt")

plot-3

# Can be broken down by panels
plot_density(data = imp, vrb = "hgt", panels = TRUE)

plot-2

# Can plot arbitrary variables 
plot_density(data = imp, vrb = c("wgt", "bmi", "phb"), panels = FALSE)

plot-7

# Can plot arbitrary variables in panels
plot_density(data = imp, vrb = c("wgt", "bmi", "phb"), panels = TRUE)

plot-4

# Can plot all variables
plot_density(data = imp)

plot-5

EdoardoCostantini avatar Oct 31 '23 18:10 EdoardoCostantini