`plot_pattern()` produces an error if only 1 pattern is requested
hanneoberman opened this issue · comments
There should be a check on the npat
argument. I think the minimum number of patterns should be 2?
ggmice::plot_pattern(mice::nhanes, square = FALSE, rotate = TRUE, cluster = "age", npat = 1)
#> Error in apply(pat[-nrow(pat), ord], 1, function(x) paste(as.numeric(x), : dim(X) must have a positive length
Created on 2023-01-25 with reprex v2.0.2
E.g. use is.vector()
and as.matrix()
to modify the md pattern object into a matrix with nrow=1
instead of a vector
Look into drop = FALSE
as alternative
@hanneoberman Note to self: check message npat
10 missing data patterns were requested and 11 missing data patterns are shown. 94 missing data patterns are hidden.
when 10 patterns are shown
The current solution (throwing an error) is not ideal. See e.g. #103
ggmice::plot_pattern(mice::nhanes, square = FALSE, rotate = TRUE, cluster = "age", npat = 1)
#> Error in ggmice::plot_pattern(mice::nhanes, square = FALSE, rotate = TRUE, : The minimum number of patterns to display is two. Please provide an integer greater than one.
Created on 2023-06-27 with reprex v2.0.2
@pepijnvink could you please revert the error message solution and fix the incorrect number of patterns in the warning message?
@pepijnvink unfortunately, this should also be done for the complete data, because md.pattern
does provide a plot.
mice::md.pattern(na.omit(mice::nhanes))
#> /\ /\
#> { `---' }
#> { O O }
#> ==> V <== No need for mice. This data set is completely observed.
#> \ \|/ /
#> `-----'
#> age bmi hyp chl
#> 13 1 1 1 1 0
#> 0 0 0 0 0
Created on 2023-06-27 with reprex v2.0.2