1

I have a graph:

p <- ggplot(iris, aes(x=Species, y=Petal.Length)) + 
  geom_boxplot(outlier.shape=NA)
p

enter image description here

How to change x labels as, for example, "set", "ver" and "virg"? I don't want to change original data.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
neringab
  • 613
  • 1
  • 7
  • 16
  • 1
    Try adding `+ scale_x_discrete(breaks = c("setosa", "versicolor", "viginica"), labels = c("set", "ver", "virg"))` to `p`? – Z.Lin Jan 09 '18 at 06:37

1 Answers1

1

you can use scale_x_discrete and just adapt the labels:

p + scale_x_discrete(labels = c("set", "ver", "virg"))

However, you have to pay attention to the order. To avoid problems you can also add the original factor levels in breaks as in @Z.Lin's comment:

p + scale_x_discrete(breaks = c("setosa", "versicolor", "viginica"), 
                     labels = c("set", "ver", "virg"))
loki
  • 9,816
  • 7
  • 56
  • 82