26

I'm using ggpairs() in the GGally package. The pairs plot is of four continuous variables, and I gave another column, a factor with 2 levels, to a colour argument which worked very nicely, both coloring the points as I expected and (bonus!) in the upper-diagonal part of the plot reporting the correlations by that factor level. My only problem is that the text reporting the correlations is too small.

Can I increase the size of the text reporting correlations in a ggpairs() plot?

I tried giving a cex argument, it seems to have no effect. I'm already using size for yet another variable; it doesn't affect the text.

For a specific example:

require(GGally)
mtcars$cyl <- as.factor(mtcars$cyl)
ggpairs(mtcars, columns = c(1, 5), colour = "cyl")

3 Answers 3

37

For anyone finding their way to this thread in 2017 and beyond, this has changed slightly.

See schloerke's answer here: https://github.com/ggobi/ggally/issues/31

ie. to change the font size used in the correlations, use the upper parameter to the ggpairs function like so:

ggpairs(mtcars, columns = c(1, 5), colour = "cyl",
    upper = list(continuous = wrap("cor", size = 9)))
Sign up to request clarification or add additional context in comments.

Comments

13

You can also specify the correlation text size in the params. For your example, you could specify a correlation font size of 12 as follows:

require(GGally)
mtcars$cyl <- as.factor(mtcars$cyl)
ggpairs(mtcars, columns = c(1, 5), colour = "cyl", params=list(corSize=12))

3 Comments

Somehow corSize makes no difference for me but size does. So it might be upper=list(params=list(size=12))). I wonder if things have changes over 2 years.
at the time of posting this comment \\ The use of params has been deprecated, you will need to use something similar to upper = list(continuous = wrap("cor", size=12))
How about fixing the spacing of each line or correlations when having groups?
4

I dont know if this is the most elegant solution, but in ggpairs you can change single plots in your plot matrix. So if you create a correlation plot like so

my_cor <- ggally_cor(mtcars, aes_string(x = "mpg", y = "drat", colour = "cyl")
          , corSize = 10)

you can insert this plot into your old matrix with

old_matrix <- ggpairs(mtcars, columns = c(1, 5), colour = "cyl")
new_matrix <- putPlot(old_matrix, my_cor, 1, 2)

1 Comment

Any idea how efficient this is? Do you pay the processing time of 1 additional plot to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.