0

I am using ggplot2 to plot a data, a toy example of which is give below. ggplot seem to sort the labels and plot the points in sorted order (first a then b and then c), however, I need the x-labels to be printed in the order it is in my table (ie, first b then a and then c.).

How can I do this?

library(ggplot2)
tmp<- data.frame(testname=c("b","b","a","a","c","c"), variable=c(40,50,40,50,40,50), value=c(0.5,0.6,0.7,0.8, 0.4, 0.8))
tmp

> tmp
  testname variable value
1        b       40   0.5
2        b       50   0.6
3        a       40   0.7
4        a       50   0.8
5        c       40   0.4
6        c       50   0.8
ggplot(tmp, aes(testname, value)) + geom_point(aes(group=variable, colour= variable), ) + theme_bw() 
learner
  • 2,582
  • 9
  • 43
  • 54

1 Answers1

1

The easiest way is to add the ordering of the factor manually before plotting

tmp$testname <- factor(tmp$testname, levels=c("b", "a", "c"))