Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Automatically expand margins in VIM::aggr plots

Tags:

r

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.

like image 554
Anaïs Fx Avatar asked Jul 04 '17 20:07

Anaïs Fx


People also ask

What is the difference between margin plot and AGGR function?

The aggr function takes all observations across all random variables and lets us visualize missingness frequencies and missingness patterns. The margin plot takes the observations from two random variables and gives us a scatterplot along with two boxplots the boxplots allow us to evaluate the MCAR vs MAR assumptions.

How to set the margins of a graph in R?

It is fairly straightforward to set the margins of a graph in R by calling the par() function with the mar (for margin!) argument. For example, par(mar=c(5.1,4.1,4.1,2.1) sets the bottom, left, top and right margins respectively of the plot region in number of lines of text. Another way is by specifying the margins in inches using the mai argument:

How to increase the size of my margins without changing region?

I would like to increase the size of my margins without altering the size of my plot region. What I'm doing is: plotting my data, then querying the values of mai (margin size in inches) and fin (figure region dimension in inches). adjusting mai by one inch at bottom and left. adjusting fin by one inch for width and one inch for height.

How do you set the margins on a plot in Python?

par (mar=c (5.1,4.1,4.1,2.1) sets the bottom, left, top and right margins respectively of the plot region in number of lines of text. Another way is by specifying the margins in inches using the mai argument: par (mai=c (1.02,0.82,0.82,0.42))


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.

like image 133
gofraidh Avatar answered Nov 15 '22 17:11

gofraidh