0

The string vector in R is such as:

C1 C2 C3 ... C10 C11 ... C16

But when I use this vector as x labels in plot I got

C1 C10 C11 ... C16 C2 C3 ... C9

How can I sort the string vector as the original series?

My code is:

tension <- read.table(file="targettension.txt")
t.frame <- data.frame(number = factor(paste(rep("C",16),(1:16),sep="")),tension = tension)
p <- ggplot(t.frame,aes(x=number,y=tension)) + geom_bar(stat="identity") 
p + geom_text(aes(label=tension),just=1.5,colour="white",size=3,angle=90)
yangdawei
  • 57
  • 6
  • 1
    Check [here](http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot) . As in the link, use the `levels` argument in 'factor' to keep the order you wanted. – akrun Aug 15 '15 at 14:08
  • 1
    you can sort character vectors like this with `gtools::mixedsort(paste0('C', 1:16))` also but like akrun says you will still have to give the levels when converting to factor – rawr Aug 15 '15 at 14:25
  • 1
    The problem is solved as you advised. Thank you very much! @akrun – yangdawei Aug 15 '15 at 14:48
  • @rawr Thank you for your answer. I'll try your method latter. – yangdawei Aug 15 '15 at 14:54

0 Answers0