[R] Problem to sort factor

Arne Brutschy abr-r-project at xylon.de
Mon Jul 16 18:14:00 CEST 2007


I'm having a problem renaming and sorting the underlying factor of a
ggplot2 based plot. Here's my code:

> delta <- ggplot(subset(data, Model==c("dyn", "dl4", "dl3")), aes(x=Problemsize, y=Fitness)) +
  geom_smooth(size=1, color="black", fill=alpha("blue", 0.2))+
  geom_point(size=0.5, aes(colour=DeltaConfig))+
  scale_colour_gradient2(expression(bold(paste(Delta,"Config"))), limits=c(0,10), midpoint=5, 
                         low="green", mid="yellow", high="red")
> delta <- delta + facet_grid(Model ~ . , margins = TRUE)
> delta

and the data
> data
   Model Problemsize Fitness DeltaConfig
1    dl1           3 81.5271      2.4495
2    dl1           3 83.1999      2.4495

I want to select a subset of the possible models and display the
resulting three plots in a column. This works fine, but: the displayed
names and order is wrong. Instead of the models "dl3","dl4","dyn"
I want to change dl* to rm* and the order to "dyn","rm3","rm4".

I hope it's understandable what I want. I tried to use factor()
function in a thousand combinations, but I don't seem to get it. Can
someone help me?

Thanks in advance,

More information about the R-help mailing list