Skip to content
Prev 276751 / 398506 Next

ggplot2 reorder factors for faceting

Hi:

(1) Here is one way to reorganize the levels of a factor:
plotData[['infection']] <- factor(plotData[['infection']],
                               levels = c('InfA', 'InfC', 'InfB', 'InfD'))

Do this ahead of the call to ggplot(), preferably after plotData is defined.

relevel() resets the baseline category of a factor, but here you want
to make multiple changes.

(2) You probably want a better title for the legend. Assuming you want
'Scale' as the title, you can add the following to labs:

labs(..., fill = 'Scale')

HTH,
Dennis


On Tue, Nov 8, 2011 at 3:51 AM, Iain Gallagher
<iaingallagher at btopenworld.com> wrote: