我想将抖动添加到散点图矩阵中.在stackoverflow上的下一页(以及其他地方)解决了这个问题:
但是那里提出的抖动问题的解决方案都涉及不推荐的代码(plotmatrix和params):
library(ggplot2)
plotmatrix(y) + geom_jitter(alpha = .2)
library(GGally)
ggpairs(y, lower = list(params = c(alpha = .2, position = "jitter")))
Run Code Online (Sandbox Code Playgroud)
我会简单地评论一下要求更新,以便不创建新问题,但这似乎需要声誉点,而且我是网站的新手.如果我在发布问题时做错了,我很抱歉.
编辑:
这是数据的样子:
> 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 ...
Run Code Online (Sandbox Code Playgroud)
这里有几次尝试获得抖动.
> 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"))
Run Code Online (Sandbox Code Playgroud)
@user20650 在问题下方的评论中回答了问题。为了完整起见,这里采用答案的形式:
使用wrap,例如:
library(GGally)
ggpairs(y, lower = list(continuous=wrap("points", position=position_jitter(height=3, width=3))))
Run Code Online (Sandbox Code Playgroud)
通过使用position = position_jitter()而不是仅使用position = "jitter"(这也有效),还可以控制附加抖动参数。