我找不到一个如何做到这一点的例子.我正在尝试使用geom_line但是避开重叠元素,但它似乎不起作用.
这是我的数据:
> sa
id ep type grp variable value
1: 1 1 typ1 1 st 1
2: 1 2 typ1 2 st 60
3: 1 3 typ1 3 st 120
4: 1 1 typ2 4 st 20
5: 1 2 typ2 5 st 60
6: 2 1 typ1 6 st 1
7: 2 2 typ1 7 st 80
8: 2 3 typ1 8 st 170
9: 2 1 typ2 9 st 10
10: 2 2 typ2 10 st 60
11: 2 3 typ2 11 st 120
12: 1 1 typ1 1 en 50
13: 1 2 typ1 2 en 100
14: 1 3 typ1 3 en 150
15: 1 1 typ2 4 en 40
16: 1 2 typ2 5 en 100
17: 2 1 typ1 6 en 40
18: 2 2 typ1 7 en 150
19: 2 3 typ1 8 en 200
20: 2 1 typ2 9 en 50
21: 2 2 typ2 10 en 90
22: 2 3 typ2 11 en 190
Run Code Online (Sandbox Code Playgroud)
这是我的简单代码试图躲避重叠值typ1和typ2
ggplot(sa,aes(x=value,y=id,group=grp,color=type)) + geom_line(size=6,position="dodge")
Run Code Online (Sandbox Code Playgroud)
这就是我所看到的.我如何躲避重叠的酒吧?
我不认为你可以垂直躲闪,但另一种选择只是增加一点躲避自己.例如:
eps = 0.05
ggplot(sa, aes(x=value, y=ifelse(type=="typ1", id + eps, id - eps),
group=grp, color=type)) +
geom_line(size=6) +
scale_y_continuous(breaks=1:2, limits=c(min(sa$id-eps), max(sa$id+eps)))
Run Code Online (Sandbox Code Playgroud)
您必须使用躲避量,轴限制等,以获得给定纵横比的所需外观.
你只能水平躲闪,但你可以通过翻转你的x和y美学来解决这个问题并使用coord_flip:
ggplot(sa, aes(x = id, y = value, group = grp, color = type)) +
geom_line(size = 6, position = position_dodge(width = 0.1)) +
coord_flip()
Run Code Online (Sandbox Code Playgroud)