I have a data frame like so:
Dataframe:
df<- data.frame(station= as.factor(rep("a", 12)),
month= as.character(c("Apr", "Aug", "Dec", "Feb", "Jan", "Jul",
"Jun", "Mar", "May", "Nov", "Oct", "Sep")),
mean= rnorm(12, 300, 10), sd= rnorm(12, 300, 1), season= c(rep("wet", 6), rep("dry", 6)))
I want to reorder the months in consecutive order so that when I input into a ggplot function data for each month occurs in the calendar order.
Failed attempt to order:
df$month<-factor(df$month, levels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
I have previously got this to work and used the following code to get the subsequent output, however I erased something along the way and believe the source of error is with improperly ordering:
Previous outputs:
p<
ggplot(df, aes(x = month, y=mean, fill=season)) +
geom_bar(stat="identity", color="black",
position=position_dodge()) +
geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.2,
position=position_dodge(.9))
p +labs(x="Month", y = "Precipitation (mm)") +
theme_bw()+
theme(legend.title = element_blank(),legend.text=element_text(size=15),legend.position="top",title= element_text(size=20), axis.text= element_text(size=10, face = "bold"), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black")) +
coord_flip()
I want to ultimately produce this figure again (note: for simplification, my example code only includes two seasons rather than the three in the image).