gappy gappy - 1 year ago 125
R Question

Customize axis labels

I have a simple

plot, in which the
variable is ordinal, taking 5 values (coded 1:5).

In the plot I would like to replace it with 5 corresponding text labels. Is it possible to do it in ggplot?

Answer Source

You should be able to do this with scale_x_discrete.

df <- data.frame(x = 1:5, y = sample(1:10, 5, TRUE))

qplot(factor(x),y, data = df) + 
scale_x_discrete(breaks = 1:5, labels=c("foo","bar","baz","phi","fum")) +
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download