ggmice icon indicating copy to clipboard operation
ggmice copied to clipboard

Automatically group by `.imp` if `group = NULL` in `ggmice()`

Open hanneoberman opened this issue 1 year ago • 2 comments

library(ggmice)
library(mice)
#> Warning: package 'mice' was built under R version 4.3.1
#> 
#> Attaching package: 'mice'
#> The following objects are masked from 'package:ggmice':
#> 
#>     bwplot, densityplot, stripplot, xyplot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.3.2
ggmice(mice(nhanes, print = FALSE), aes(bmi, group = .imp)) + 
  geom_density() 

Created on 2023-12-07 with reprex v2.0.2

hanneoberman avatar Dec 07 '23 10:12 hanneoberman

If data is mids, and group inside aes() is NULL, then set group = .imp

hanneoberman avatar Dec 07 '23 13:12 hanneoberman

To do this, edit here: https://github.com/amices/ggmice/blob/6a69f135ad8b42512446ad67a36486a80a4febef/R/ggmice.R#L112C5-L113C64

hanneoberman avatar Dec 07 '23 13:12 hanneoberman