12

I'm using facets in ggplot2 to plot the distribution of expression in a large number of genes. My plotting commands are pretty generic:

p <- ggplot(top_n,aes(x=value,fill=ptype))
p <- p + geom_density(alpha = 0.2)
p <- p + facet_wrap(~probe,...)

they just plot the data in top_n as distributions coloured according to the ptype variable. It looks great.

Some of these genes, however, are more important than others. It would be really cool to highlight those genes which are transcription factors (TFs), for example. One way would be for me to change the colour title box over each facet corresponding to a TF, or the background colour, or something like that.

Is there a way for me to set options of the plots on a per-facet basis?

Digging around in the p object hasn't turned up anything I can use, though I'm probably missing something!

zx8754
  • 52,746
  • 12
  • 114
  • 209
Mike Dewar
  • 10,945
  • 14
  • 49
  • 65

1 Answers1

14

You could use geom_rect with infinite extents and a fill colour that varies from facet to facet.

This has been done in a solution here: Conditionally change panel background with facet_grid?

Arthur Yip
  • 5,810
  • 2
  • 31
  • 50
hadley
  • 102,019
  • 32
  • 183
  • 245