Search code examples
rggplot2bubble-chartggally

How to make a bubble chart with GGally::ggpairs?


I would like to create a bubble chart matrix using GGally::ggpairs.

Defining the point/bubble size in ggplot2 is easy using the size argument:

library("ggplot2")
data(mtcars)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(aes(size = qsec)) 

However, with GGally::ggpairs this does not work. The following code produces this:

library("GGally")
ggpairs(mtcars[ ,c("mpg", "wt", "disp")], 
        size=mtcars$qsec)

points obviously not varying in size=qsec

And the following code does not even produce a plot

ggpairs(mtcars[ ,c("mpg", "wt", "disp")], 
        size="qsec")
> error in eval(expr, envir, enclos) : object 'qsec' not found

Any ideas how to fix this?


Solution

  • You get the last error because qsec is not present in the subset c("mpg", "wt", "disp").

    ggpairs(mtcars[ ,c("mpg", "wt", "disp", "qsec")], columns = 1:3, size = "qsec")
    

    enter image description here