Skip to content

Instantly share code, notes, and snippets.

@padamson
Created February 17, 2016 02:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save padamson/3ce8174228d5607b78be to your computer and use it in GitHub Desktop.
Save padamson/3ce8174228d5607b78be to your computer and use it in GitHub Desktop.
Add two regression lines to plots in ggpairs
require(datasets)
data("swiss")
require(GGally)
require(ggplot2)
my_fn <- function(data, mapping, ...){
p <- ggplot(data = data, mapping = mapping) +
geom_point() +
geom_smooth(method=loess, fill="red", color="red", ...) +
geom_smooth(method=lm, fill="blue", color="blue", ...)
p
}
g = ggpairs(swiss,columns = 1:4, lower = list(continuous = my_fn))
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment