gpt4 book ai didi

r - 如何将抖动添加到 ggpairs 中的散点图矩阵?

转载 作者:行者123 更新时间:2023-12-04 11:30:23 26 4
gpt4 key购买 nike

我想向散点图矩阵添加抖动。这个问题在 stackoverflow 的下一页(没有其他地方)得到解决:

How to produce a meaningful draftsman/correlation plot for discrete values

但是,建议的抖动问题的两种解决方案都涉及不推荐使用的代码(plotmatrix 和 params):

library(ggplot2)
plotmatrix(y) + geom_jitter(alpha = .2)

library(GGally)
ggpairs(y, lower = list(params = c(alpha = .2, position = "jitter")))

我会简单地评论要求在那里进行更新,以免创建新问题,但这似乎需要声誉点,而我是该网站的新手。如果我在发布问题时做错了什么,我深表歉意。

编辑:

数据如下所示:
> str(EHRound4.subset)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 301 obs. of 22 variables:
$ Subject# : int 1 2 3 4 6 7 8 13 14 16 ...
$ Condition : Factor w/ 2 levels "CDR","Mturk": 1 1 1 1 1 1 1 1
1 1 ...
$ Launch4 : int 5 8 8 5 8 5 3 8 5 6 ...
$ NewSong4 : int 6 8 8 6 8 6 8 8 8 7 ...
$ StudCom5 : int 6 5 8 3 1 3 4 8 7 7 ...
$ Textbook5 : int 8 1 8 3 1 7 8 8 8 8 ...

这里有几次尝试获得抖动。
> ggpairs(EHRound4.subset, columns = 3:6, 
ggplot2::aes(colour=Condition), lower = list(geom_jitter(alpha = .2)))

> ggpairs(EHRound4.subset, columns = 3:6,
ggplot2::aes(colour=Condition, alpha=.2), lower = list(geom_jitter()))

> ggpairs(EHRound4.subset, columns = 3:6,
ggplot2::aes(colour=Condition, alpha=.2, position="jitter"))

最佳答案

@user20650 在问题下方的评论中回答了问题。为了完整起见,这里采用答案的形式:

使用 wrap , 如:

library(GGally)
ggpairs(y, lower = list(continuous=wrap("points", position=position_jitter(height=3, width=3))))

通过使用 position = position_jitter()而不仅仅是 position = "jitter" (这也有效)额外的抖动参数也可以控制。

关于r - 如何将抖动添加到 ggpairs 中的散点图矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45044157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com