-1

How do I change my label on x axis? I have numbers on axis but want characters. I found something with date which

scale_x_date(breaks=datebreaks) + theme(axis.text.x=element_text(angle30, hjust=1)

I have tried


scale_x_discrete(breaks=c("1","2","3"),labels=c("name1","name2","name3") + thame(axis.text.x=element_text(angle30, hjust=1)

but it is not working.

Dezdi
  • 11
  • 6
  • 3
    (1) I'm assuming you did an erroneous copy/paste, since I don't see `thame` in my `"ggplot2"` install; I edited your question including that typo, please correct me if I over-stepped. (2) Without sample data and all of the relevant code (since this code is incomplete), it's a little difficult to try to reproduce this. Please give us a reproducible example: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Mar 25 '19 at 23:05

1 Answers1

0

I believe the following should allow you to relabel the tick marks on the x-axis by either explicitly stating the breaks and labels separately or explicitly stating labels and breaks together:

# Solution 1
p + scale_x_discrete(breaks=c("0.5","1","2"),
        labels=c("label 1", "label 2", "label 3"))

# Solution 2 : same plot as solution 1
p + scale_x_discrete(labels=c("0.5" = "label 1", "1" = "label 2",
                              "2" = "label 3"))
SPJ
  • 116
  • 8
  • yes I did the same as your solution one shows tried the solution 2 but only different complete remove my label so I have nothing there except the xlab but the the number gone. any idea why? – Dezdi Mar 26 '19 at 20:00