How to change the display order of the labels of the x axis

Hello,
I would like to know how to change the display order of the labels of the x axis in each of my area
For example in my area1, I would like my "names" to be displayed as follows: "Yier", "Axo", "Hute", my area2 : "Chyt", "Pite".
Moreover, how to change the order of display of the areas, for example to have 2,1,3 instead of 1,2,3

df <- data.frame (value  = c(96.14,94.62,92.41,91.27,84.14,74.91,82.14),
                  names = c("Axo", "Pite", "Yier","Molu","Hute","Chyt","Chut"),
                  area = c("1","2","1","3","1","2","3"))

df %>% 
  ggplot(aes(x = names,value)) +
  geom_col() + 
  facet_grid(~factor(area,levels = c("1","2","3")),
             scale = "free_x", space = "free_x", switch = "x") 

Thanks

Just like with area use levels

library(tidyverse)

df <- data.frame (value  = c(96.14,94.62,92.41,91.27,84.14,74.91,82.14),
                  names = c("Axo", "Pite", "Yier","Molu","Hute","Chyt","Chut"),
                  area = c("1","2","1","3","1","2","3"))

df %>%
    mutate(names = factor(names, levels = c("Chyt", "Pite", "Yier", "Axo",
                                            "Hute", "Chut", "Molu"))) %>% 
    ggplot(aes(x = names,value)) +
    geom_col() + 
    facet_grid(~factor(area, levels = c("2","1","3")),
               scale = "free_x",
               space = "free_x",
               switch = "x")

Created on 2022-07-21 by the reprex package (v2.0.1)

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.