2012-05-31 50 views
1

我学习上的其他类似的问题,但似乎无法得到这个工作对我的数据。堆栈区域图中的R

我瞄准了这一结果:

desired output

这是我的数据帧:

 
    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))) 

我得到这样的结果:

not working

我怎样才能得到这个工作?

回答

5

因为Room变量被当作一个因素,因此不会作出任何意义有连接实线这是行不通的。

绘制:

ggplot(tp, aes(x=1:3, y=MB, fill=Direc)) + 
    geom_area() 

给出结果我想你期待。您可以添加:

ggplot(tp, aes(x=1:3, y=MB, fill=Direc)) + 
    geom_area() + 
    scale_x_discrete(labels=tp$Room) 

修复标签。