'Sorting of a numeric vector in the ggplot graph after group by variables and pipe using facet_wrap

I have a code like the following:

library(dplyr)
library(ggplot2)

#Calculate some means
mean_data <- group_by(df, Duration, Time.elapsed,P_R_coef, R_L_coef) %>%
  summarise(mean_A = mean(Number.of.theories.to.be.discovered, na.rm = TRUE), mean_B = mean(Number.of.published.theories.CK, na.rm = TRUE), mean_C = mean(Number.of.refuted.theories, na.rm = TRUE), mean_D = mean(Number.of.true.published.theories, na.rm = TRUE), mean_E = mean(Number.of.false.published.theories, na.rm = TRUE), mean_F = mean(Theta, na.rm = TRUE))

#Plot some means
ggplot(mean_data %>% mutate(group = paste(as.numeric(P_R_coef),as.numeric(P_R_coef),Duration, sep="-")),
  aes(Time.elapsed)) +
  geom_line(aes(y = mean_A, colour = "Nb.T.to.be.discovered")) + 
  geom_line(aes(y = mean_B, colour = "Nb.T.published.CK")) +
  geom_line(aes(y = mean_C, colour = "Nb.T.refuted")) +
  geom_line(aes(y = mean_D, colour = "Nb.true.published")) +
  geom_line(aes(y = mean_E, colour = "Nb.false.published")) +
  geom_line(aes(y = mean_F*200, colour = "Theta")) +
  facet_wrap(~group, scales = "free", labeller = label_both)+
  theme_classic()+
  labs(x = "Time", y = "Mean", color = "Epistemic landscape") +
  scale_y_continuous(
    "Mean", 
    sec.axis = sec_axis(~ ./200, name = "Theta")
  )

When plotting, the ordering of the plot I get is incorrect. As can be seen in the last row of the plot, facet_wrap shows P_R_coef 10 before P_R_coef 2.

enter image description here

I have tried coercing numeric, integer and character vector types, but that doesn't help. My goal is that in the last row of the graph, 2 and 3 appear before 10. I appreciate suggestions.

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source