使用facet_wrap

时间:2016-12-23 11:33:23

标签: r plot ggplot2 gridextra facet-wrap

我有一个数据框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

这包含由字母ACTG组成的所有可能的三元组,这些三元组按类型分组和计数,例如C=>TG=>A代表两个不同的样本S1S2

我想为每种类型制作图表(C=>TG=>A)。我可以在一个情节中做到这一点:

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

作为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

根据我的理解,facet_wrap明确假设每个方面的轴都相同,所以我的facet_wrap图中有三个不存在该类型的三元组的间隙。

任何人都可以帮我制作类似于facet_wrap的图,但轴值只对应于可用数据吗?

这是facet_wrap还是gridextra的工作?

0 个答案:

没有答案