首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在GGally中使用ggpairs绘制黄土估计值?

如何在GGally中使用ggpairs绘制黄土估计值?
EN

Stack Overflow用户
提问于 2014-03-27 03:54:11
回答 2查看 1.3K关注 0票数 1

我尝试了一下GGally包。尤其是ggpairs函数。然而,我想不出如何在平滑的情况下使用lm而不是loess。有什么想法吗?下面是我的代码:

代码语言:javascript
复制
require(GGally)
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),]
ggpairs(diamonds.samp[,c(1,5)], 
        lower = list(continuous = "smooth"),
        params = c(method = "loess"),
        axisLabels = "show")

谢谢!

另外,与plotmatrix函数相比,ggpairs要慢得多。因此,在大多数情况下,我只使用ggplot2中的plotmatrix。

EN

回答 2

Stack Overflow用户

发布于 2014-04-04 08:00:24

文档上没有说,所以请使用源代码,Luke

  1. 您可以使用以下命令更深入地挖掘源代码:

ls('package:GGally')

GGally::ggpairs

... and browse every function it references ...

seems like the args get mapped into ggpairsPlots and then -> plotMatrix which then gets called

因此,显然不支持显式地选择smoother,只能选择continuous = "smooth"。如果它的行为类似于ggplot2:geom_smooth,它会在内部自动找出调用哪个受支持的平滑器(对于<1000个数据点是loess,对于>=1000是gam )。您可能希望单步执行调试器,以查看绘图中发生了什么。我试着追查来源,但我的眼睛呆滞了。--

或2.浏览https://github.com/ggobi/ggally/blob/master/R/ggpairs.r 2013年4月14日

代码语言:javascript
复制
#' upper and lower are lists that may contain the variables 'continuous',
#' 'combo' and 'discrete'. Each element of the list is a string implementing
#' the following options: continuous = exactly one of ('points', 'smooth',
#' 'density', 'cor', 'blank') , ...
#'
#' diag is a list that may only contain the variables 'continuous' and 'discrete'.
#' Each element of the diag list is a string implmenting the following options:
#' continuous = exactly one of ('density', 'bar', 'blank');
票数 1
EN

Stack Overflow用户

发布于 2020-10-29 18:29:38

通常,最好编写您自己的函数以供其使用。Adapted from this answer回答类似的问题。

代码语言:javascript
复制
library(GGally)
diamonds_sample = diamonds[sample(1:dim(diamonds)[1],200),]

# Function to return points and geom_smooth
# allow for the method to be changed
custom_function = function(data, mapping, method = "loess", ...){
      p = ggplot(data = data, mapping = mapping) + 
      geom_point() + 
      geom_smooth(method=method, ...)

      p
    }

# test it  
ggpairs(diamonds_sample,
    lower = list(continuous = custom_function)
)

生成以下内容:

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

https://stackoverflow.com/questions/22671686

复制
相关文章

相似问题

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