Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的堆积面积图_R_Ggplot2 - Fatal编程技术网

R中的堆积面积图

R中的堆积面积图,r,ggplot2,R,Ggplot2,我已经研究了其他类似的问题,但似乎无法让我的数据工作 我的目标是: 这是我的数据框: 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 我得到这个结果: 如何使其工作?这将不起作用,因为房间变量被视为一个因子,因此连续线连接没有任何意义

我已经研究了其他类似的问题,但似乎无法让我的数据工作

我的目标是:

这是我的数据框:

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

修复标签

这将不起作用,因为
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)
修复标签