The following plot
Is generated with the following code:
library(GGally)
dat <- read.csv("http://www.ats.ucla.edu/stat/data/tobit.csv")
ggpairs(dat[, c("read", "math", "apt")])
How can I add the correlation line for each of the scatter plot above?
Something like this?
ggpairs(dat[, c("read", "math", "apt")],lower = list(continuous = "smooth", params = c(method = "loess", fill = "blue"))
You can customize the scatterplots in the lower triangle as you wish within a function like the one below:
library(GGally)
dat <- ggplot2::diamonds[1:1000, c("x", "y", "z")] # Example data
# Customize your scatterplots as you wish here:
lowerfun <- function(data, mapping) {
ggplot(data = data, mapping = mapping)+
geom_point(alpha = .25) +
geom_smooth(method = "loess", formula = y ~ x,
fill = "blue", color = "red", size = 0.5)
}
# Plot the scatterplot matrix
ggpairs(dat, lower = list(continuous = wrap(lowerfun)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.