Skip to content

Instantly share code, notes, and snippets.

@EhsanKhedive
Forked from padamson/multi_smooth_ggpairs.R
Created April 18, 2024 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EhsanKhedive/cac30eee3d974e042257ab8b70f9be02 to your computer and use it in GitHub Desktop.
Save EhsanKhedive/cac30eee3d974e042257ab8b70f9be02 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