reorder categories in a correlation matrix in GGally

Hi there! I am trying to create a correlation matrix with GGally, folowing the next example:

    # Quick display of two cabapilities of GGally, to assess the distribution and correlation of variables 
    library(GGally)
 
    # From the help page:
    data(flea)
    ggpairs(flea, columns = 2:4, ggplot2::aes(colour=species)) 

Rplot

There are three categories: Concina, Heikert and Heptapot. There is any way to reorder them in a non-alphabetical order?

Thank you!

You could do this simply by changing the ordering of the levels of the species factor:

flea <- flea %>% 
  mutate(species = factor(species, 
                          levels=c("Heikert.", "Concinna", "Heptapot.")))
ggpairs(flea, columns = 2:4, ggplot2::aes(colour=species)) 

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.

Thats exactly what I needed! Thank you so much!