R ggplot中的数据顺序和颜色

R ggplot中的数据顺序和颜色,r,ggplot2,R,Ggplot2,我有一个数据框中的资产 Date C B A E D 2011-06-30 20449251 2011906 0 0 0 2011-09-30 20766092 1754940 0 0 0 2011-12-31 15242138 1921684 0 0 0 2012-03-31 15811841 2186571 0

我有一个数据框中的资产

Date        C       B       A       E       D
2011-06-30 20449251 2011906       0       0       0
2011-09-30 20766092 1754940       0       0       0
2011-12-31 15242138 1921684       0       0       0
2012-03-31 15811841 2186571       0       0       0
2012-06-30 16221813 2026042 2423039 2419517       0
2012-09-30 16155686 2261729 2563734 1160693       0
2012-12-31 16297839 2231341 2592015 1151989       0
2013-03-31 14627046 2441132 2769681 1249464       0
2013-06-30 14186185 2763985 2615053 1260893       0
2013-09-30 14039954 2780167 2698988 1264244       0
2013-12-31 13832117 3081687 2962113 1318903       0
2014-03-31 14177177 3133202 3077684 1353243       0
2014-06-30 14503900 3235089 3196623 1415319       0
2014-09-30 12561057 3227862 3048216 1413446 2073068
然后我融化并绘制出一个堆积面积图

library('ggplot2')
library('reshape2')
colorscheme = scale_fill_brewer(type="qual",palette = 2)

df = melt(data,id.var="Date",variable.name="Manager")
df[,3] = as.numeric(df[,3])

#Stacked Area
layout(c(1,1))
p = ggplot(df,aes(x=Date,y=value,group=Manager,fill=Manager))+
  geom_area(position="fill") + colorscheme 
print(p)
这很有效:

现在我想要最后一行(即当前日期)的饼图

我得到以下信息:

忽略格式,我的问题是关于颜色选择。经理认为颜色不相配。管理器面积图中的颜色现在是管理器C的颜色。我意识到这是因为饼图是按管理器名称排序的,而
数据中的管理器顺序没有排序

我无法控制如何接收数据。有没有办法重新排列
数据
和/或
df
(数据融合)以便第一个图形按管理器顺序排列?或者更改数据发送到饼图的方式


谢谢,

与其在因子水平上乱搞,不如在
数据中最后一行的
日期之前对
df
进行子集划分

ggplot(df[df$Date==tail(data,1)$Date,],aes(x=1,y=value,fill=Manager)) + 
  geom_bar(stat="identity") + colorscheme + coord_polar(theta="y") 

因子级别的顺序与
fill=factor(rownames(df1),levels=rownames(df1))的顺序不同。
ggplot(df[df$Date==tail(data,1)$Date,],aes(x=1,y=value,fill=Manager)) + 
  geom_bar(stat="identity") + colorscheme + coord_polar(theta="y")