难以使用ggplot2 geom_smooth method = loess绘制数据?

时间:2018-04-16 21:25:03

标签: r ggplot2 loess

我对此非常陌生,我实际上并不了解绘图方法之间的差异,但是loess似乎给了我最丰富的图表,考虑到我有一个小的 - ish数据集(n = ~300)。我尝试使用facet_wrap按性别划分我的数据,而loess对男性来说很好,但不适合女性。

这是我用来绘制图表的代码:

ggplot(data = df, aes(x = STM, y = ATTRACTcomp, color=Harasser_Attractiveness)) +
     geom_point(position="jitter", size=0.5) +
     facet_wrap( ~Participant_Gender, 
                 labeller = as_labeller(c("Female" = "Female Participants", "Male" = "Male Participants"))) +
     geom_smooth(method = "loess") +
     labs(title = paste(strwrap("Interaction of Harasser Attractiveness, Participant Gender 
                                and SOI on Attraction/Flattery", 50), collapse="\n"),
          x = "Participant Short-term Mating Orientation", y = "Participant Attraction/Flattery", 
          color="Harasser:") +
     theme(plot.title = element_text(hjust = 0.5), 
           plot.caption = element_text(hjust=0, margin=margin(t=15,0,0,0)), 
           legend.position="top", legend.margin = margin(1,0,0,0), legend.title = element_text(size=10), 
           legend.text = element_text(size=9), legend.key.size=unit(c(12), "pt")) +
     scale_color_grey(start = .6, end = .1)

问题在于我为男性图表获得了平滑的条件平均线,但不是女性图表。

以下是我的错误消息:

Warning messages:
1: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  at  0.97
2: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  radius  0.0009
3: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  all data on boundary of neighborhood. make span bigger
4: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  pseudoinverse used at 0.97
5: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  neighborhood radius 0.03
6: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  reciprocal condition number  1
7: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  zero-width neighborhood. make span bigger
8: In simpleLoess(y, x, w, span, degree = degree, parametric = parametric,  :
  There are other near singularities as well. 1
9: Computation failed in `stat_smooth()`:
NA/NaN/Inf in foreign function call (arg 5) 

有趣的是,多个y变量会发生这种情况:女性图总是缺少线条而且我总是会遇到类似的错误。当我忽略facet_wrap并尝试仅绘制女性参与者的数据框子集时,也会发生这种情况。

根据我的理解阅读有关类似错误消息的线程,geom_smooth(或stat_smooth中的一些计算,因为我认为它在引擎盖下调用)返回无限值。 (我相当确定这里的相关变量中没有NA s / NaN。)问题是,关于此错误的所有线程都假设您有权访问生成无限值的进程,我不是。

有些人一直说当你的值恰好等于1时就会发生这种情况。我确实有很多ATTRACTcomp(我的y变量)等于1的值,但他们都是男人和女人,所以我不知道为什么我能够为男性而不是女性获得正确的线条。

同样有用的绘图方法也会有所帮助。

我不确定重现此错误所需的最小数据量是多少,所以我只想包含一个只包含图表中使用的变量的数据框:

> dput(df)
structure(list(STM = c(6L, 4L, 7L, 3L, 6L, 7L, 3L, 1L, 4L, 6L, 
1L, 1L, 6L, 4L, 6L, 3L, 5L, 2L, 5L, 5L, 4L, 1L, 1L, 4L, 4L, 1L, 
1L, 2L, 3L, 4L, 3L, 4L, 6L, 6L, 1L, 1L, 1L, 5L, 1L, 1L, 2L, 4L, 
2L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 7L, 2L, 1L, 6L, 4L, 1L, 1L, 1L, 
1L, 1L, 4L, 1L, 4L, 5L, 1L, 1L, 7L, 4L, 1L, 1L, 1L, 1L, 2L, 1L, 
1L, 1L, 2L, 1L, 1L, 1L, 4L, 1L, 1L, 2L, 1L, 1L, 2L, 4L, 5L, 1L, 
1L, 1L, 1L, 4L, 1L, 2L, 1L, 7L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 4L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 
7L, 3L, 1L, 1L, 1L, 1L, 7L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 2L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 7L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 5L, 4L, 1L, 1L, 
1L, 1L, 1L, 2L, 1L, 7L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 5L, 2L, 
1L, 1L, 6L, 2L, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 1L, 1L, 1L, 4L, 1L, 
1L, 1L, 1L, 1L, 2L, 4L, 1L, 1L, 1L, 6L, 1L, 1L, 1L, 3L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 
4L, 5L, 5L, 1L, 1L, 4L, 4L, 1L, 7L, 1L, 1L, 4L, 3L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 5L, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 4L, 7L, 1L, 
1L, 2L, 1L, 1L, 4L, 5L, 5L, 2L, 1L, 4L, 7L, 3L, 5L, 4L, 5L, 4L, 
5L, 7L, 7L, 3L), ATTRACTcomp = c(6.53125, 4.25, 5.84375, 4.21875, 
5.4375, 2.15625, 3.96875, 4.71875, 3.875, 5.875, 2, 1.87096774193548, 
5.65625, 4.5625, 5.65625, 4.53125, 5.375, 1, 5.125, 3.5625, 4.71875, 
3.96875, 4.03125, 4.15625, 4.28125, 4.6875, 3.53125, 2.40625, 
4.15625, 2.8125, 4.54838709677419, 3.40625, 4.09677419354839, 
4.625, 4.53125, 1.90625, 2.32258064516129, 3.53125, 1.90625, 
3.46666666666667, 2.2258064516129, 3.625, 4.40625, 4.625, 2.125, 
4.3125, 1.9375, 2.4375, 3.96875, 4.875, 5.16129032258065, 2.1875, 
1.0625, 3.34375, 3.40625, 1.90625, 1, 3.75, 3.45161290322581, 
1.93548387096774, 3.53125, 1.84375, 2.71875, 3.40625, 2.59375, 
4.09375, 4.125, 3.96875, 4.34375, 1, 2.6875, 3.6875, 1.09375, 
1.0625, 1.375, 1.96875, 2.25, 1.28125, 1.03125, 3.8125, 4.0625, 
2.09375, 1.25, 2.34375, 2.90625, 1, 1.5625, 1.25, 1.5625, 1.34375, 
2.46875, 1.96875, 1.15625, 1.59375, 1.09375, 2.03125, 1, 5.40625, 
3.59375, 1.1875, 1.90625, 1.8125, 1.56666666666667, 1.0625, 3.58064516129032, 
4.90625, 6.28125, 1.0625, 2.9375, 1.09375, 1.78125, 1, 2.09375, 
1.03125, 4.75, 2.71875, 1, 5.96875, 1.42307692307692, 1, 1.0625, 
1.0625, 1.03125, 1.90625, 1.28125, 1.15625, 1.03125, 1.09375, 
6.53125, 2.15625, 1.03125, 1.59375, 2, 1.1875, 1.1875, 1.34375, 
2.25, 1.03125, 1.0625, 1.3125, 1, 1.5, 1, 2.375, 1.1875, 1.0625, 
1.35483870967742, 1, 1.09375, 1.15625, 1, 1, 1.5625, 2, 1, 1.03125, 
1.03125, 1, 1.125, 1, 6.6875, 1.1875, 1.51612903225806, 1.0625, 
1.125, 1, 1.15625, 1.4375, 1.25, 1.0625, 1.03125, 1.41935483870968, 
1, 1, 2.09375, 1.15625, 1, 1, 1, 3.06451612903226, 1, 1, 1, 1, 
1, 1, 1, 1.03125, 1.1875, 1.875, 1, 1, 1.5625, 3.25, 1.3125, 
1.46875, 2.375, 3.78125, 3.25, 1.21875, 1.25, 1, 1.65625, 1, 
1, 6.0625, 1.90625, 6.80645161290323, 1.21875, 1.65625, 1, 1.28125, 
1.26666666666667, 1.03125, 1, 2.3125, 4.125, 3.59375, 2.40625, 
5.34375, 4.84375, 3.65625, 1.28125, 1.5625, 3.6875, 1.53125, 
1.09375, 1.21875, 2.15625, 1.25, 1, 1.375, 1.3125, 1.125, 1.5625, 
1.25, 1.5, 1.28125, 2.21875, 3.09375, 3.15625, 1, 1.15625, 4.75, 
1, 1.61290322580645, 1.90322580645161, 1.74193548387097, 1.46875, 
1, 1.1875, 1.1875, 1.03125, 1.34375, 1.78125, 1, 1.8125, 1, 1, 
1.2258064516129, 1.0625, 1.25, 1.59375, 1.09375, 1, 1.03125, 
3.9375, 1.46875, 2.71875, 7, 3.875, 3.40625, 2.4375, 2.53125, 
2.09677419354839, 1.28125, 1, 1.8125, 1, 1.78125, 1.0625, 1, 
1, 1.03125, 1.09375, 1.4375, 1, 1.625, 1.03125, 1.03125, 1.40625, 
1.84375, 3.40625, 3.21875, 1, 1, 6.6875, 2.71875, 2.5625, 3.96875, 
2.8125, 2.125, 4.21875, 3.65625, 3.25, 1.53125, 5.8125, 3.5625, 
4.78125, 1.625, 5.875, 3.21875, 3.41935483870968, 3.21875, 6, 
6.34375, 6, 1.40625), Harasser_Attractiveness = structure(c(1L, 
1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 
2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 
2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 
2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 
1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 
2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 
2L,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1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L), .Label = c("Female", 
"Male"), class = "factor")), .Names = c("STM", "ATTRACTcomp", 
"Harasser_Attractiveness", "Participant_Gender"), row.names = c(NA, 
-318L), class = "data.frame")

1 个答案:

答案 0 :(得分:4)

作为noted by joran,我认为您的数据太偏斜,无法适应此平滑功能。我会重新考虑使用这种方法,这种数据不平衡,因此集中在STM == 1上。可以使它显示一些线条,例如下面通过移除前{50}的女性观察值STM == 1,但这对于离散的x轴来说实际上并不是正确的显示(即使理论上变量是连续的) ,您的实际数据被测量为离散的)。事实上,平滑的线条是误导性的(女性线条到目前为止STM == 7是否确实下降,或者这只是因为你只有两点?

我会更喜欢使用factor(STM)调用中的aes(),如下所示的boxplot方法。在这里,我们可以使用geom_text在图表底部按箱图添加计数,使每个箱图基于的内容更清晰。我们仍然得到一般情况,即较高的STM与较高的ATTRACTComp相关联,但Harasser_Attractiveness会有所不同,但我们不再基于非常少的数据点建议平滑的关系线。

library(tidyverse)

df <- structure(list(STM = c(6L, 4L, 7L, 3L, 6L, 7L, 3L, 1L, 4L, 6L, 
                           1L, 1L, 6L, 4L, 6L, 3L, 5L, 2L, 5L, 5L, 4L, 1L, 1L, 4L, 4L, 1L, 
                           1L, 2L, 3L, 4L, 3L, 4L, 6L, 6L, 1L, 1L, 1L, 5L, 1L, 1L, 2L, 4L, 
                           2L, 1L, 1L, 1L, 1L, 1L, 2L, 4L, 7L, 2L, 1L, 6L, 4L, 1L, 1L, 1L, 
                           1L, 1L, 4L, 1L, 4L, 5L, 1L, 1L, 7L, 4L, 1L, 1L, 1L, 1L, 2L, 1L, 
                           1L, 1L, 2L, 1L, 1L, 1L, 4L, 1L, 1L, 2L, 1L, 1L, 2L, 4L, 5L, 1L, 
                           1L, 1L, 1L, 4L, 1L, 2L, 1L, 7L, 5L, 4L, 1L, 1L, 1L, 1L, 1L, 4L, 
                           1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 
                           7L, 3L, 1L, 1L, 1L, 1L, 7L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                           1L, 2L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 
                           1L, 1L, 1L, 1L, 1L, 1L, 1L, 7L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 
                           1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 
                           1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 5L, 4L, 1L, 1L, 
                           1L, 1L, 1L, 2L, 1L, 7L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 5L, 2L, 
                           1L, 1L, 6L, 2L, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 1L, 1L, 1L, 4L, 1L, 
                           1L, 1L, 1L, 1L, 2L, 4L, 1L, 1L, 1L, 6L, 1L, 1L, 1L, 3L, 1L, 1L, 
                           1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 
                           4L, 5L, 5L, 1L, 1L, 4L, 4L, 1L, 7L, 1L, 1L, 4L, 3L, 1L, 1L, 1L, 
                           1L, 1L, 1L, 2L, 2L, 5L, 1L, 1L, 1L, 1L, 5L, 2L, 1L, 4L, 7L, 1L, 
                           1L, 2L, 1L, 1L, 4L, 5L, 5L, 2L, 1L, 4L, 7L, 3L, 5L, 4L, 5L, 4L, 
                           5L, 7L, 7L, 3L), ATTRACTcomp = c(6.53125, 4.25, 5.84375, 4.21875, 
                                                            5.4375, 2.15625, 3.96875, 4.71875, 3.875, 5.875, 2, 1.87096774193548, 
                                                            5.65625, 4.5625, 5.65625, 4.53125, 5.375, 1, 5.125, 3.5625, 4.71875, 
                                                            3.96875, 4.03125, 4.15625, 4.28125, 4.6875, 3.53125, 2.40625, 
                                                            4.15625, 2.8125, 4.54838709677419, 3.40625, 4.09677419354839, 
                                                            4.625, 4.53125, 1.90625, 2.32258064516129, 3.53125, 1.90625, 
                                                            3.46666666666667, 2.2258064516129, 3.625, 4.40625, 4.625, 2.125, 
                                                            4.3125, 1.9375, 2.4375, 3.96875, 4.875, 5.16129032258065, 2.1875, 
                                                            1.0625, 3.34375, 3.40625, 1.90625, 1, 3.75, 3.45161290322581, 
                                                            1.93548387096774, 3.53125, 1.84375, 2.71875, 3.40625, 2.59375, 
                                                            4.09375, 4.125, 3.96875, 4.34375, 1, 2.6875, 3.6875, 1.09375, 
                                                            1.0625, 1.375, 1.96875, 2.25, 1.28125, 1.03125, 3.8125, 4.0625, 
                                                            2.09375, 1.25, 2.34375, 2.90625, 1, 1.5625, 1.25, 1.5625, 1.34375, 
                                                            2.46875, 1.96875, 1.15625, 1.59375, 1.09375, 2.03125, 1, 5.40625, 
                                                            3.59375, 1.1875, 1.90625, 1.8125, 1.56666666666667, 1.0625, 3.58064516129032, 
                                                            4.90625, 6.28125, 1.0625, 2.9375, 1.09375, 1.78125, 1, 2.09375, 
                                                            1.03125, 4.75, 2.71875, 1, 5.96875, 1.42307692307692, 1, 1.0625, 
                                                            1.0625, 1.03125, 1.90625, 1.28125, 1.15625, 1.03125, 1.09375, 
                                                            6.53125, 2.15625, 1.03125, 1.59375, 2, 1.1875, 1.1875, 1.34375, 
                                                            2.25, 1.03125, 1.0625, 1.3125, 1, 1.5, 1, 2.375, 1.1875, 1.0625, 
                                                            1.35483870967742, 1, 1.09375, 1.15625, 1, 1, 1.5625, 2, 1, 1.03125, 
                                                            1.03125, 1, 1.125, 1, 6.6875, 1.1875, 1.51612903225806, 1.0625, 
                                                            1.125, 1, 1.15625, 1.4375, 1.25, 1.0625, 1.03125, 1.41935483870968, 
                                                            1, 1, 2.09375, 1.15625, 1, 1, 1, 3.06451612903226, 1, 1, 1, 1, 
                                                            1, 1, 1, 1.03125, 1.1875, 1.875, 1, 1, 1.5625, 3.25, 1.3125, 
                                                            1.46875, 2.375, 3.78125, 3.25, 1.21875, 1.25, 1, 1.65625, 1, 
                                                            1, 6.0625, 1.90625, 6.80645161290323, 1.21875, 1.65625, 1, 1.28125, 
                                                            1.26666666666667, 1.03125, 1, 2.3125, 4.125, 3.59375, 2.40625, 
                                                            5.34375, 4.84375, 3.65625, 1.28125, 1.5625, 3.6875, 1.53125, 
                                                            1.09375, 1.21875, 2.15625, 1.25, 1, 1.375, 1.3125, 1.125, 1.5625, 
                                                            1.25, 1.5, 1.28125, 2.21875, 3.09375, 3.15625, 1, 1.15625, 4.75, 
                                                            1, 1.61290322580645, 1.90322580645161, 1.74193548387097, 1.46875, 
                                                            1, 1.1875, 1.1875, 1.03125, 1.34375, 1.78125, 1, 1.8125, 1, 1, 
                                                            1.2258064516129, 1.0625, 1.25, 1.59375, 1.09375, 1, 1.03125, 
                                                            3.9375, 1.46875, 2.71875, 7, 3.875, 3.40625, 2.4375, 2.53125, 
                                                            2.09677419354839, 1.28125, 1, 1.8125, 1, 1.78125, 1.0625, 1, 
                                                            1, 1.03125, 1.09375, 1.4375, 1, 1.625, 1.03125, 1.03125, 1.40625, 
                                                            1.84375, 3.40625, 3.21875, 1, 1, 6.6875, 2.71875, 2.5625, 3.96875, 
                                                            2.8125, 2.125, 4.21875, 3.65625, 3.25, 1.53125, 5.8125, 3.5625, 
                                                            4.78125, 1.625, 5.875, 3.21875, 3.41935483870968, 3.21875, 6, 
                                                            6.34375, 6, 1.40625), Harasser_Attractiveness = structure(c(1L, 
                                                                                                                        1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 
                                                                                                                        2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 
                                                                                                                        2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 
                                                                                                                        2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 
                                                                                                                        2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 
                                                                                                                        1L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 
                                                                                                                        1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 
                                                                                                                        2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 
                                                                                                                        2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 
                                                                                                                        2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 
                                                                                                                        2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 
                                                                                                                        1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 
                                                                                                                        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                        1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                                                                                                        2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                                                                                                        2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                                                                                                        2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
                                                                                                                        2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L), .Label = c("Attractive", 
                                                                                                                                                                                        "Unattractive"), class = "factor"), Participant_Gender = structure(c(2L, 
                                                                                                                                                                                                                                                             2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 
                                                                                                                                                                                                                                                             2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 
                                                                                                                                                                                                                                                             1L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 
                                                                                                                                                                                                                                                             2L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                                                                                                                                                             1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 
                                                                                                                                                                                                                                                             1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 
                                                                                                                                                                                                                                                             1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 
                                                                                                                                                                                                                                                             1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
                                                                                                                                                                                                                                                             1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 
                                                                                                                                                                                                                                                             1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 
                                                                                                                                                                                                                                                             1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
                                                                                                                                                                                                                                                             1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 
                                                                                                                                                                                                                                                             2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 
                                                                                                                                                                                                                                                             1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 
                                                                                                                                                                                                                                                             2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L), .Label = c("Female", 
                                                                                                                                                                                                                                                                                                                             "Male"), class = "factor")), .Names = c("STM", "ATTRACTcomp", 
                                                                                                                                                                                                                                                                                                                                                                     "Harasser_Attractiveness", "Participant_Gender"), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                     -318L), class = "data.frame")

ggplot(
  data = df %>%
    arrange(Participant_Gender, STM) %>%
    slice(50:nrow(.)), 
  mapping = aes(x = STM, y = ATTRACTcomp, color = Harasser_Attractiveness)
  ) +
  geom_jitter() +
  geom_smooth() +
  facet_wrap(~ Participant_Gender,
    labeller = as_labeller(c("Female" = "Female Participants", "Male" = "Male Participants"))
  ) +
  labs(
    title = paste(strwrap("Interaction of Harasser Attractiveness, Participant Gender 
                             and SOI on Attraction/Flattery", 50), collapse = "\n"),
    x = "Participant Short-term Mating Orientation",
    y = "Participant Attraction/Flattery",
    color = "Harasser:"
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    plot.caption = element_text(hjust = 0, margin = margin(t = 15, 0, 0, 0)),
    legend.position = "top",
    legend.margin = margin(1, 0, 0, 0),
    legend.title = element_text(size = 10),
    legend.text = element_text(size = 9),
    legend.key.size = unit(c(12), "pt")
  )
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : pseudoinverse used at 0.97
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 1.03
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 0
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 1
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
#> at 0.97
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
#> 1.03
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : reciprocal
#> condition number 0
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : There are other
#> near singularities as well. 1
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : pseudoinverse used at 0.97
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 2.03
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 0
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 4
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
#> at 0.97
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
#> 2.03
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : reciprocal
#> condition number 0
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : There are other
#> near singularities as well. 4

ggplot(
  data = df, 
  mapping = aes(x = factor(STM), y = ATTRACTcomp, color = Harasser_Attractiveness)
) +
  geom_boxplot() +
  facet_wrap(
    ~ Participant_Gender,
    labeller = as_labeller(c("Female" = "Female Participants", "Male" = "Male Participants"))
  ) +
  geom_text(
    data = df %>%
      count(Participant_Gender, STM, Harasser_Attractiveness) %>%
      mutate(label = str_c(n), yloc = 0.75),
    mapping = aes(y = yloc, label = label),
    position = position_dodge(width = 0.75)
  ) +
  labs(
    title = paste(strwrap("Interaction of Harasser Attractiveness, Participant Gender 
                             and SOI on Attraction/Flattery", 50), collapse = "\n"),
    x = "Participant Short-term Mating Orientation",
    y = "Participant Attraction/Flattery",
    color = "Harasser:"
  ) +
  theme(
    plot.title = element_text(hjust = 0.5),
    plot.caption = element_text(hjust = 0, margin = margin(t = 15, 0, 0, 0)),
    legend.position = "top",
    legend.margin = margin(1, 0, 0, 0),
    legend.title = element_text(size = 10),
    legend.text = element_text(size = 9),
    legend.key.size = unit(c(12), "pt")
  )

reprex package(v0.2.0)创建于2018-04-16。