As far as I can see my code is correct so why is the reorder function not working? Ideally I do not want to have to order the data itself prior to plotting.
DOC_output_clean2 <- data.frame("Trap_type" = c("DOC 150", "DOC 150", "DOC 150",
"DOC 200", "DOC 200", "DOC 200",
"DOC 250", "DOC 250", "DOC 250",
"DOC 250", "DOC 250", "Fenn", "Fenn",
"Fenn", "Fenn", "Fenn", "Fenn"),
"Hedgcapt" = c("0.02", "0.0", "0.04", "0.001", "0.02",
"0.0", "0.002", "0.0", "0.2", "0.03",
"0.004", "0.0", "0.35", "0.07", "0.5",
"0.015", "0.7"))
DOC_output_clean$Trap_type <- as.factor(DOC_output_clean$Trap_type)
DOC_output_clean$Hedgcapt <- as.numeric(DOC_output_clean$Hedgcapt)
DOC_output_clean %>%
ggplot(aes(x = reorder(Trap_type, -Hedgcapt), y= Hedgcapt)) +
geom_point(aes(x = Trap_type),
position = position_jitterdodge(jitter.width = 4, jitter.height=0,
dodge.width = 0.9),
alpha = 0.2) +
geom_bar(position="dodge", stat="summary", fun.y = 'mean', alpha = 0.7)+
aes(color = Trap_type, fill = Trap_type) +
geom_errorbar(stat='summary', position=position_dodge(0.9), width=0.4) +
coord_cartesian(ylim = c(0,1)) +
theme_classic() +
theme(axis.text.x = element_text(angle = 90)) +
xlab("\nTrap type") + ylab("Mean corrected trap catch\n") +
theme(legend.position = "none")
This is the result I get currently, and I want it to be re-ordered: