我尝试了一下GGally包。尤其是ggpairs函数。然而,我想不出如何在平滑的情况下使用lm而不是loess。有什么想法吗?下面是我的代码:
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。
发布于 2014-04-04 08:00:24
文档上没有说,所以请使用源代码,Luke
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日
#' 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');发布于 2020-10-29 18:29:38
通常,最好编写您自己的函数以供其使用。Adapted from this answer回答类似的问题。
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)
)生成以下内容:

https://stackoverflow.com/questions/22671686
复制相似问题