How do I change the order of elements on the X axis?
Right now the order is as shown on the picture. The order should be: Control, YUN_S1.0, AMB_F471, AMB_V001, AMB_V038, HAN016, HNP007, CON21
The data are ordered as they should, but Rstudio puts them in alfabetical order.
This is the current code:
add_el <- theme_bw() +
theme(axis.text.y =element_text(size=16),
axis.text.x = element_text(size=16, angle = 75, hjust = 1),
axis.title=element_text(size=16),
legend.title=element_blank(),
legend.text = element_text(size = 14),
legend.position="bottom",
strip.background = element_rect(colour = "black", fill = "white"),
strip.text.x = element_text(size=18, face="bold"),
strip.text.y = element_text(size=16))
ggplot(FC, aes(x = Probiotics, y = Concentration, fill= Species)) +
geom_bar(stat="identity", color="black",
position=position_dodge()) +
Thanks!
geom_errorbar(aes(
ymin = Concentration-SD,
ymax = Concentration+SD),
width=.2,
position=position_dodge(.9)) +
geom_col() +
labs(x = "Conditions", y= "Concentration (log(10) cells/mL)") +
add_el
I have tried:
FC <- read.xlsx(xlsxFile = "YUNexperiment1.xlsx", sheet = 1, skipEmptyRows = TRUE)
FC <- FC %>% mutate(Probiotics=factor(Probiotics, levels=c("Control", "YUN_S1.0", "AMB_F471",
"AMB_V001", "AMB_V038", "HAN016", "HNP007", "CON21"), ordered=TRUE))