I want to change the order of the stacked bar plot in R? I am sharing the example below and the green bar will be under the blue bar, how can I can this order? See the code below.
d1<-data.frame(Gene=c("DNA","DNA",
"RNA","RNA",
"XX","XX"),
Gender=c("M","F","M","F","M","F"),
p_value=c( 0.5, 0.1,
0.6,0.01,
0.07,0.02
))
p<-d1 %>%
ggplot(aes(x=forcats::fct_reorder(Gene,p_value), y=p_value, fill=Gender)) +
geom_col(color="black",position=position_dodge()) +
coord_flip() +
scale_fill_manual(values=c('#6495ED','#2E8B57'))+
labs(x="Gene", y="p-value")