考虑这些数据(请注意,这foo实际上是一个因素.):
foo bar outcome ci
1 a 0.683333333 0.247447165
2 b 0.941666667 0.180356565
3 c 0.783333333 0.335337789
1 d 0.866666667 0.204453706
2 e 0.45 0.303059647
3 f 0.325 0.340780173
Run Code Online (Sandbox Code Playgroud)
我想用bar每个foo值绘制多个s ,其中outcome带有CI和误差条.这是我做的:
ggplot(ex, aes(foo, outcome, label = bar)) +
geom_point(position = position_dodge(.1)) +
geom_errorbar(aes(ymin = outcome - ci, ymax = outcome + ci), position = position_dodge(.1)) +
geom_text(hjust = 2)
Run Code Online (Sandbox Code Playgroud)
我明白了:

但是我想让它躲避错误条和点,这样我才能看到重叠.使用position_jitter那样做,但它是完全随机的(或"笨重的") - 我不希望这样.
如何抵消个别观察?
Hen*_*rik 10
一种可能性是group通过'bar'.请注意,我还dodge了geom_text.
dodge <- position_dodge(.1)
ggplot(data = df, aes(x = foo, y = outcome, group = bar, label = bar)) +
geom_point(position = dodge) +
geom_errorbar(aes(ymin = outcome - ci, ymax = outcome + ci), position = dodge) +
geom_text(hjust = 2, position = dodge)
Run Code Online (Sandbox Code Playgroud)
