用ggpairs()

问题描述 投票:0回答:3

i想将the
stat_binhex()
统计量与
ggplot2
函数(
ggpairs()
r软件包)一起使用。  例如,我想在this情节中使用
GGally
而不是
stat_binhex()。这可能吗?

感谢您的帮助!enter image description here

geom_point()
r ggplot2 ggally
3个回答
4
投票

    

screenshot

当前版本的

2
投票
(2.1.2)这比以前要容易得多:不需要任何低级黑客攻击,并且可以更轻松地将其与

GGally

自定义的其他方面更容易结合。
ggpairs

enter image description here cannot认为,这仍然不是ggally_hexbin <- function (data, mapping, ...) { p <- ggplot(data = data, mapping = mapping) + geom_hex(...) p } ggpairs(df, ## use 'ggally_hexbin' for continuous × continuous plots lower = list(continuous = "hexbin", ## use default plots for all other variable types combo = "facethist", discrete = "facetbar", na = "na"))


1
投票
的自定义的一部分。

lukea的答案上建造,让我们将其转换为一个函数:
设置要求并定义功能:

ggpair()

收集一些数据:

require(ggplot2)[enter image description here][1] require(GGally) require(hexbin) ggpairs_hex <- function(df, hexbins = 10) { # REF: https://stackoverflow.com/questions/20872133/using-stat-binhex-with-ggpairs p <- ggpairs(df, lower="blank") seq <- 1:ncol(df) for (x in seq) for (y in seq) if (y>x) p <- putPlot(p, ggplot(df, aes_string(x=names(df)[x],y=names(df)[y])) + stat_binhex(bins = hexbins), y,x) return(p) }

测试函数:
require(MASS)

# data generation from:
# https://predictivehacks.com/how-to-generate-correlated-data-in-r/
set.seed(312)
# create the variance covariance matrix
sigma<-rbind(c(1,-0.8,-0.7), c(-0.8,1, 0.9), c(-0.7,0.9,1))
# create the mean vector
mu<-c(10, 5, 2) 
# generate the multivariate normal distribution
df<-as.data.frame(MASS::mvrnorm(n=10000, mu=mu, Sigma=sigma))


enter image description here enter image description here @@ben-bolker的答案似乎效果很好,但是是否有任何方法可以为所有或每个pannel添加传奇? 谢谢! enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.