Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get ggplot to order facets correctly?

Tags:

r

ggplot2

I am trying to facet about 14 plots based on a variable that runs from 2-14. The plots show up in the order: 10,11,12,13,14,15,2,3,4,5,6,7,8,9

How do I get them to order from 2-15?

update: ok, so I made it a factor using data$var=as.factor(data$var). The Levels are Levels: 10 11 12 13 14 15 2 3 4 5 6 7 8 9

How do I reorder those?

like image 905
Maiasaura Avatar asked Jul 22 '10 18:07

Maiasaura


1 Answers

data$var <- factor(data$var, levels = sort(unique(data$var)))
like image 167
hadley Avatar answered Oct 21 '22 03:10

hadley