0

I want my `X-axis label to be arranged as it is in the data frame and not re-arranged alphabetically as it is here

df1 <- read.table(text =
                    "nbb_RMSE  9 0.2402482
                    mbb_RMSE  9 0.1023012
                    cbb_RMSE  8 0.2031448
                    tmbb_RMSE 4 0.2654746
                    tcbb_RMSE 9 0.4048711")

colnames(df1) <- c("Methods", "lb", "RMSE")

df1 |>
  dplyr::mutate(colour = fct_reorder(Methods, RMSE)) |>
  ggplot2::ggplot(aes(Methods, RMSE, colour = colour)) + 
  ggplot2::geom_point(size = 4) + 
  ggplot2::geom_segment(aes(Methods, xend = Methods, yend = RMSE, y = 0)) + 
  ggplot2::scale_color_manual(values = c("green", "yellowgreen", "yellow", 
                            "orange", "red"),
                 labels = c(9, 8, 9, 9, 4), name = "lb") + 
  ggplot2::theme_bw(base_size = 16)

What I want

I want nbb_RMSE, mbb_RMSE, cbb_RMSE tmbb_RMSE, tcbb_RMSE chronologically in X-axis label.

Note

I want its legend to remain as it is (from green to red)

Edit

The following answers does not work in my case Order discrete x scale by frequency/value and How do you specifically order ggplot2 x axis instead of alphabetical order?

Daniel James
  • 1,381
  • 1
  • 10
  • 28

0 Answers0