Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize lines in ggpairs [GGally]

Tags:

r

ggplot2

ggally

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?
like image 891
neversaint Avatar asked Dec 15 '22 13:12

neversaint


1 Answers

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

like image 99
WCC Avatar answered Jan 05 '23 04:01

WCC