Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloring points based on variable with R ggpairs

Tags:

r

ggplot2

ggally

I'm trying to reproduce the figure in https://tgmstat.wordpress.com/2013/11/13/plot-matrix-with-the-r-package-ggally/ with the code

require(GGally)
data(tips, package="reshape")
ggpairs(data=tips, title="tips data", colour = "sex") 

However, in the plot I get the points are not colored based on sex, instead they are all the same color. I get the following warning

Warning message: In warn_if_args_exist(list(...)) : Extra arguments: 'colour' are being ignored. If these are meant to be >aesthetics, submit them using the 'mapping' variable within ggpairs with >ggplot2::aes or ggplot2::aes_string.

I've tried adding ggplot2::aes(colour = sex), but that did not work either.

Does anyone else here have the same problem? I'm using R version 3.3.1 and GGally_1.2.0.

Thanks.

like image 375
Ana Avatar asked Jul 18 '16 22:07

Ana


1 Answers

GGally has been under fairly rapid development, so it's not surprising that a blog post from 2013 has out-of-date code. When I run your code with GGally 1.2.0 I get the same warning. It works for me if I add the mapping:

require(GGally)
data(tips, package="reshape")
g1 <- ggpairs(data=tips, title="tips data",
  mapping=ggplot2::aes(colour = sex),
  lower=list(combo=wrap("facethist",binwidth=1)))

Following the wiki page for the wrap() incantation to stop complaints about needing to set binwidth in stat_bin ...

enter image description here

like image 134
Ben Bolker Avatar answered Nov 03 '22 06:11

Ben Bolker