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)
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?
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")
链接地址: http://www.djcxy.com/p/30914.html