How to customize lines in ggpairs [GGally]

neversaint picture neversaint · Jun 16, 2015 · Viewed 9.4k times · Source

I have the following plot:

enter image description here

Generated with this code:

library("GGally")
data(iris)
ggpairs(iris[, 1:4], lower=list(continuous="smooth", params=c(colour="blue")),
  diag=list(continuous="bar", params=c(colour="blue")), 
  upper=list(params=list(corSize=6)), axisLabels='show')

My questions are:

  1. How can I change the correlation line to be red, now it's black.
  2. And the correlation line is buried under the scatter plot. I want to put it on top. How can I do that?

Answer

WCC picture WCC · Mar 15, 2016

Check your version of GGally by packageVersion("GGally") and upgrade your GGally to version 1.0.1

library("GGally")
library("ggplot2")
data(iris)

lowerFn <- function(data, mapping, method = "lm", ...) {
  p <- ggplot(data = data, mapping = mapping) +
    geom_point(colour = "blue") +
    geom_smooth(method = method, color = "red", ...)
  p
}

ggpairs(
  iris[, 1:4], lower = list(continuous = wrap(lowerFn, method = "lm")),
  diag = list(continuous = wrap("barDiag", colour = "blue")),
  upper = list(continuous = wrap("cor", size = 10))
)

enter image description here