首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在GGally相关图矩阵上添加直线拟合

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

Stack Overflow用户
提问于 2015-06-16 07:28:13
回答 2查看 1.4K关注 0票数 1

下图

使用以下代码生成:

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

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

EN

回答 2

Stack Overflow用户

发布于 2015-06-16 07:40:42

像这样的东西?

代码语言:javascript
复制
ggpairs(dat[, c("read", "math", "apt")],lower = list(continuous = "smooth", params = c(method = "loess", fill = "blue"))

票数 1
EN

Stack Overflow用户

发布于 2021-04-05 21:29:56

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

代码语言:javascript
复制
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)))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30856602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档