I have a graph:
p <- ggplot(iris, aes(x=Species, y=Petal.Length)) +
geom_boxplot(outlier.shape=NA)
p
How to change x labels as, for example, "set", "ver" and "virg"? I don't want to change original data.
I have a graph:
p <- ggplot(iris, aes(x=Species, y=Petal.Length)) +
geom_boxplot(outlier.shape=NA)
p
How to change x labels as, for example, "set", "ver" and "virg"? I don't want to change original data.
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"))