Disable automatic alphabetical order in facet_wrap

Hello,
How can I disable the automatic alphabetical order of the plot?
In the following code, I want to plot the facet plot in monthly wise i.e. Jan, Feb..Dec.

Thanks

mat_d=data.frame(
  V1=runif(48))
mat_d%>% 
  mutate(month=rep(month.abb[seq (1:12)],each=4),
         var=rep(c("R","m","RR", "S"),times=12))


ggplot(mat_d1, aes(y = var, x = V1, fill = month)) +
  geom_segment(aes(x = 0, y = var, xend = V1, yend = var), color = "black") +
  geom_point(aes(color=ifelse(var %in% c("R"), "R",
                              ifelse(var %in% c("m"), "m", 
                                     ifelse(var %in% c("RR"), "RR", "S")
                              )), size = 5 )
  )+
  facet_wrap(~month)+
  scale_fill_discrete(guide = "none")+
  scale_color_discrete(name = "")

The default ordering of a factor is alphabetical. You can set a different ordering using the levels argument of the factor function. Try

mat_d=data.frame(
  v1=runif(48))
mat_d1 <- mat_d%>% 
  mutate(month=rep(month.abb[seq (1:12)],each=4),
         var=rep(c("R","m","RR", "S"),times=12),
         month = factor(month, levels = month.abb[seq (1:12)]))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.