I want to have the order of variables corresponding to a specific order of colors. So I explicitly assign the order of colors values to be corresponding to the break in scale_fill_manual(), as shown in the following scripts:
figure <- ggplot(df, aes(factor(groups), values, fill = parameter)) +
theme_bw(base_size = 20, base_family = "Helvetica") +
geom_bar(stat="identity", position = "dodge") +
labs(x = xlabel_name, y = ylabel_name)
figure + scale_fill_manual(values = c("red", "blue", "green", "yellow", "brown", "black"),
breaks = c('COLI_index', 'P_less_30k', 'employ_rat', 'NonWt_Pct', 'P_75k_200k', 'P_more_200')
)
Basically, I am expecting:
red: COLI_index
blue: P_less_30k
green: employ_rat
yellow:NonWt_Pct
brown: P_75k_200k
black: P_more_200
But in the figure I got, the order of the colors for each variables are:
red: COLI_index
blue: employ_rat
green: NonWt_Pct
yellow:P_75k_200k
brown: P_less_30k
black: P_more_200
By the way, I am doing a grouped bar graph like this:
Any hints for which part is wrong?
The source data frame (df) is as following:
groups parameter values
NonWt_Pct Lowest NonWt_Pct 33.5
employ_rat Lowest employ_rat 80.5
P_less_30k Lowest P_less_30k 15.0
P_75k_200k Lowest P_75k_200k 41.7
P_more_200 Lowest P_more_200 12.1
COLI_index Lowest COLI_index 49.2
NonWt_Pct1 Second NonWt_Pct 53.7
employ_rat1 Second employ_rat 78.2
P_less_30k1 Second P_less_30k 26.9
P_75k_200k1 Second P_75k_200k 28.3
P_more_2001 Second P_more_200 7.6
COLI_index1 Second COLI_index 68.3
NonWt_Pct2 Third NonWt_Pct 76.3
employ_rat2 Third employ_rat 69.8
P_less_30k2 Third P_less_30k 44.7
P_75k_200k2 Third P_75k_200k 15.8
P_more_2002 Third P_more_200 6.4
COLI_index2 Third COLI_index 83.4
NonWt_Pct3 Highest NonWt_Pct 91.4
employ_rat3 Highest employ_rat 59.0
P_less_30k3 Highest P_less_30k 60.6
P_75k_200k3 Highest P_75k_200k 9.8
P_more_2003 Highest P_more_200 3.5
COLI_index3 Highest COLI_index 91.6