我想将抖动添加到散点图矩阵中。这个问题在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"))发布于 2018-12-07 20:46:22
@user20650在问题下面的评论中回答了这个问题。为了完整起见,以下是答案的形式:
使用wrap,例如:
library(GGally)
ggpairs(y, lower = list(continuous=wrap("points", position=position_jitter(height=3, width=3))))通过使用position = position_jitter()而不只是position = "jitter" (它也可以工作),还可以控制额外的抖动参数。
https://stackoverflow.com/questions/45044157
复制相似问题