library(ggplot2) #example stored in baseplot ID <- 1:600 values <- c(rnorm(150, mean=25, sd=5), rnorm(150, mean=30, sd=4), rnorm(150, mean=15, 3), rnorm(150, mean=40, sd=5)) category <- c(rep("blue", 150), rep("red", 150), rep("green", 150), rep("yellow", 150)) df <- data.frame(ID, category, values) baseplot <- ggplot(df, aes(category, values, fill=category)) + geom_boxplot() + scale_fill_manual(values=c("blue", "green", "red", "yellow")) baseplot #rename the labels with scale_x_discrete(labels=) baseplot + scale_x_discrete(labels=c("blue group", "green group", "red group", "yellow group")) #problem when reordering categories baseplot + scale_x_discrete(limits=c("yellow", "red", "green", "blue"), labels=c("blue group", "green group", "red group", "yellow group")) #indicate the right order both in limits= and label= baseplot + scale_x_discrete(limits=c("yellow", "red", "green", "blue"), labels=c("yellow group", "red group", "green group", "blue group")) #use limits= to set the order and use labels= to bind the new labels to the categories baseplot + scale_x_discrete(limits=c("blue", "red", "yellow", "green"), labels=c("yellow" = "yellow group", "blue" = "blue group", "red" = "red group", "green" = "green group")) #easy to change the order and keep the correct labels baseplot + scale_x_discrete(limits=c("red", "yellow", "blue", "green"), labels=c("yellow" = "yellow group", "blue" = "blue group", "red" = "red group", "green" = "green group"))