繁体   English   中英

如何在 GGally 相关图矩阵上添加线拟合

[英]How to add line fit on GGally correlation plot matrix

下面的情节

在此处输入图片说明

使用以下代码生成:

library(GGally)
dat <- read.csv("http://www.ats.ucla.edu/stat/data/tobit.csv")
ggpairs(dat[, c("read", "math", "apt")])

如何为上面的每个散点图添加相关线?

像这样的东西?

ggpairs(dat[, c("read", "math", "apt")],lower = list(continuous = "smooth", params = c(method = "loess", fill = "blue"))

在此处输入图片说明

您可以在如下所示的函数中根据需要自定义下三角形中的散点图:

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)))

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM