R: Automatically expand margins in VIM::aggr plots

Viewed 3024

I'm trying to visualise missing data with the R package VIM. I'm using R version 3.4.0 with RStudio

I've used the function aggr() but the colnames of my dataframe seem to be too long. Thus, some labels of the x axis don't appear. I would like to increase the space at the bottom of the x axis.

library(VIM)
aggr(df)

Here is my dataframe df and the plot I obtain Here is my dataframe df and the plot I obtain

I've tried with par() function but it doesn't change anything.

aggr(df,mar=c(10,5,5,3))

or

par(mar=c(10,5,5,3))
g=aggr(df,plot=FALSE)
plot(g)

I can reduce the font size with cex.axis but then labels are too small.

aggr(df,cex.axis=.7)

Here is the plot with small axis labels: Here is the plot with small axis labels

I've not find a lot of examples using aggr() that's why I ask for your help. Thank you in advance.

1 Answers

I think you are looking for a graphical parameter oma which will allow you to resize the main plot. The help reference states:

For plot.aggr, further graphical parameters to be passed down. par("oma") will be set appropriately unless supplied (see par).

In your case you could do something like:

aggr(df, prop = T, numbers = F, combined = F,
 labels = names(df), cex.axis = .9, oma = c(10,5,5,3))

Obviously, you need to play around with cex.axis and other parameters to find out what works best for your data.

Related