Code:
CashSurDef <- ggplot(data=wdiSSA_CashSurDef.df,aes(x=Country.Name, y=avg, fill=colour))
CashSurDef <- CashSurDef + geom_bar(stat="identity",position=position_dodge(),alpha=.75) + theme_bw()
CashSurDef <- CashSurDef + scale_fill_manual(breaks = wdiSSA_CashSurDef.df$Country.Name,
values = unique(as.character(wdiSSA_CashSurDef.df$colour)))
CashSurDef <- CashSurDef + scale_y_continuous(breaks=seq(-25,25,2.5)) + geom_hline(yintercept=0, linetype="dashed", colour="blue", size=1.1)
CashSurDef <- CashSurDef + labs(title="Cash surplus/deficit (% of GDP) (Average 2005-2012)", y="", x="Country") + coord_flip()
CashSurDef <- CashSurDef + theme(plot.title=element_text(face="bold", size=rel(2), hjust=0.5, vjust=1.5),
axis.text.x=element_text(color="black", size=rel(1.8), hjust=0.5, vjust=0.5),
axis.text.y=element_text(color="black", size=rel(1.8), hjust=1),
axis.title.x=element_text(face="bold", color="black", size=rel(1.6), hjust=0.5, vjust=0.2),
axis.title.y=element_text(color="black", size=rel(1.6), hjust=0.5, vjust=0.2),
strip.text=element_text(face="bold", size=rel(1.8)),
legend.text=element_text(face="bold", size=rel(1.25)),
legend.title=element_blank(),
legend.position="bottom")
CashSurDef
Code1:
Unemploy <- ggplot(data=wdiSSA_Unemploy.df,aes(x=Country.Name, y=avg, fill=colour))
Unemploy <- Unemploy + geom_bar(stat="identity",position=position_dodge(),alpha=.75) + theme_bw()
Unemploy <- Unemploy + scale_fill_manual(breaks = wdiSSA_Unemploy.df$Country.Name,
values = unique(as.character(wdiSSA_Unemploy.df$colour)))
Unemploy <- Unemploy + scale_y_continuous(breaks=seq(0,35,5)) + geom_hline(yintercept=5, linetype="dashed", colour="blue", size=1.1)
Unemploy <- Unemploy + labs(title="Average unemployment rate (2005-2012), total (%)", y="", x="Country") + coord_flip()
Unemploy <- Unemploy + theme(plot.title=element_text(face="bold", size=rel(2), hjust=0.5, vjust=1.5),
axis.text.x=element_text(color="black", size=rel(1.8), hjust=0.5, vjust=0.5),
axis.text.y=element_text(color="black", size=rel(1.8), hjust=1),
axis.title.x=element_text(face="bold", color="black", size=rel(1.6), hjust=0.5, vjust=0.2),
axis.title.y=element_text(color="black", size=rel(1.6), hjust=0.5, vjust=0.2),
strip.text=element_text(face="bold", size=rel(1.8)),
legend.text=element_text(face="bold", size=rel(1.25)),
legend.title=element_blank(),
legend.position="bottom")
Unemploy
Result: Result1:
Question: I am trying to plot the data and use the predefined fill captured by the column "colour" in "Data", and which was added based on the conditional statement: if(avg>0, tan3, grey)
. When I plot though, the colour filling gets reversed as you may observe in the picture "Result". I applied the same method for other variables in my data (cf. "Data1", "Result1"), and it worked perfectly. Any thoughts, suggestions?
Cheers