我在SO上研究了其他类似的问题,但似乎无法使我的数据工作.
我的目标是这个结果:
这是我的数据框:
Room Direc MB Alley-10 Rx 1 Alley-11 Rx 7 Alley-12 Rx 11 Alley-10 Tx 23 Alley-11 Tx 17 Alley-12 Tx 20
当我跑:
ggplot(tp, aes(x=Room,y=MB)) + geom_area(aes(fill=factor(Direc)))
Run Code Online (Sandbox Code Playgroud)
我得到这个结果:
我怎样才能使这个工作?
这不起作用,因为Room
变量被视为一个因素,因此连续的线连接没有任何意义.
绘图:
ggplot(tp, aes(x=1:3, y=MB, fill=Direc)) +
geom_area()
Run Code Online (Sandbox Code Playgroud)
给出我认为你期待的结果.然后你可以添加:
ggplot(tp, aes(x=1:3, y=MB, fill=Direc)) +
geom_area() +
scale_x_discrete(labels=tp$Room)
Run Code Online (Sandbox Code Playgroud)
修复标签.