0

I know this question has been asked/answered in a few different incarnations -- I'm failing to see the solution to the flavor of my problem.

I'd like all the "methods" in the plot below to be plotted in descending order as a function of the mean AAC (that is the value plotted in geom_point()). Each of these points is grouped by "Period" -- there are two periods -- historic, and future.

current code:

df_level3_MW %>% 
  mutate(Period=fct_relevel(Period,"historic","future")) %>% 
  ggplot(aes(x = reorder(Period,-mean_AAC),
           y = mean_AAC,
           group = interaction(factor(Tech),factor(TypeID),method)))+
  geom_point(size = 1.8,
             alpha = .8,
             position = position_dodge(0.9),
             aes(color = factor(method),
                 shape = factor(TypeID)))+
  geom_errorbar(aes(ymin=min_AAC, 
                    ymax=max_AAC,
                    color = factor(method),
                    linetype = factor(Tech)),
                position=position_dodge(0.9),
                size = 0.3,
                width=0.5)+
  labs(title = "Distribution of AAC across all gcms, methods",
       colour="method",
       shape="TypeID",
       linetype="Tech")+
  ylab("Region-Weighted AAC")+
  scale_color_manual(values=plasma_pal)+
  scale_linetype_manual(values=c("solid","11","22"))

enter image description here

bearcub
  • 313
  • 4
  • 11
  • This isn't a solution to the question itself (that would be to make method a factor and order it by mean_aac), but I doubt you'll find a color scheme where that many colors will be discernible. Somewhere between 7 and 10 colors is where most humans stop being able to tell them apart. [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example with a sample of data – camille Feb 22 '22 at 03:03
  • The order of plotting is determined by the ordering of factor levels. So make sure the levels of the methods factor are set the way you expect. – IRTFM Feb 22 '22 at 03:13
  • 1
    Hard to say without example data, but faceting often messes up value ordering. See the `reorder_within` function used in this question for a neat solution: https://stackoverflow.com/q/71120774/17303805 – zephryl Feb 22 '22 at 03:41

0 Answers0