Level-dependent axis vales using facet_wrap

45 views Asked by At

I have a dataframe so:

>head(so)
  tri trans freq sample
1 ACA  C=>T   13     S1
2 ACC  C=>T    9     S1
3 ACG  C=>T    6     S1
4 ACT  C=>T   14     S1
5 CCA  C=>T   24     S1
6 CCC  C=>T   16     S1

>tail(so)
   tri trans freq sample
59 GGG  G=>A   18     S2
60 GGT  G=>A    6     S2
61 TGA  G=>A   15     S2
62 TGC  G=>A   10     S2
63 TGG  G=>A    7     S2
64 TGT  G=>A   22     S2

This contains all possible triplets composed of the letters A, C, T and G which are grouped and counted by type e.g. C=>T, G=>A for two different samples S1, S2.

I would like to make plots for each type (C=>T, G=>A). I can do this for on one plot:

so <- read.table("muts.txt", header = FALSE)
colnames(so)=c("tri", "trans", "freq", "sample")

ggplot(so, aes(tri,freq, group = sample)) +
    geom_point(aes(colour = sample, shape = trans))

enter image description here

And as a facet_wrap:

ggplot(so, aes(tri,freq, group = sample)) + 
    geom_point(aes(colour = sample)) + 
    facet_wrap(~ trans) +
    theme(axis.text.x = element_text(angle=90))

enter image description here

As I understand it, facet_wrap explicitly assumes that axes are the same for each facet, so I have gaps on my facet_wrap plot for triplets that don't exist for that type.

Can anyone help me produce similar plots to facet_wrap but with axis values corresponding only to available data?

Is this a job for facet_wrap or gridextra?

0

There are 0 answers