2

I am attempting to use the aggr() function of the VIM package to plot missing data patterns. My plots don't show the frequencies/proportions of missing data patterns to the outside of the right-side axis. Should look like this. I'm getting an error that there is "not enough horizontal space to display frequencies".

library(VIM)
aggr(sleep, prop = T, numbers = T)

I don't do much base R plotting. I think this has something to do with margins. I reviewed this informative tutorial on margins, but I did not find my way to a solution.

Eric Green
  • 7,385
  • 11
  • 56
  • 102
  • I have no problem. Did you run it inside a clean session of R? –  Dec 18 '15 at 02:18
  • 1
    I just cleared the environment and reran. Same issue. RStudio Version 0.99.489 on Mac. – Eric Green Dec 18 '15 at 02:21
  • Simply running these two lines? No customized `par` defined previously? –  Dec 18 '15 at 02:28
  • I'm not very familiar with base plotting, but I ran `dev.off()` and checked `par()$mar`: `5.1 4.1 4.1 2.1`. That's the default, right? – Eric Green Dec 18 '15 at 02:31
  • Yes, but according to the code source, this error is related to `par("pin")`. –  Dec 18 '15 at 02:32
  • 2
    OK, got it. `par("pin")`: `2.902222 4.824444`. I found this custom function to reset par and it worked: http://stackoverflow.com/questions/5789982/reset-par-to-the-default-values-at-startup. Thanks for pointing me in the right direction. – Eric Green Dec 18 '15 at 02:35
  • 1
    Create an answer. Might be useful for `aggr` users facing the same error. –  Dec 18 '15 at 02:43
  • will do. it's not working on my actual use case yet, but i did resolve for the toy example. i'll try to resolve for my case first. – Eric Green Dec 18 '15 at 02:44

1 Answers1

3

I had two problems: one localized and one related to aggr().

1) This function helped me to reset par("pin"). Resetting made the toy example work.

resetPar <- function() {
    dev.new()
    op <- par(no.readonly = TRUE)
    dev.off()
    op
}
par(resetPar())

2) My actual use case was still failing with the same horizontal space error. I realized I needed to set the cex.numbers parameter of aggr() to something less than 1.

Community
  • 1
  • 1
Eric Green
  • 7,385
  • 11
  • 56
  • 102