実際のデータセットと簡略化されたダミー データセットの両方を使用して、ggplot で facet_wrap を使用しようとすると、困惑する問題が発生します。各染色体を別々に示して、複数の個人のゲノム全体でヘテロ接合性をプロットしようとしています。
私のダミーデータ:
chr1 123000 124000 2 0.00002 26 0.00026 indiv1
chr1 124000 125000 3 0.00003 12 0.00012 indiv1
chr1 125000 126000 1 0.00001 6 0.00006 indiv1
chr1 126000 126000 2 0.00002 14 0.00014 indiv1
chr2 123000 124000 6 0.00006 20 0.00020 indiv1
chr2 124000 125000 0 0.00000 12 0.00012 indiv1
chr1 123000 124000 2 0.00002 26 0.00026 indiv2
chr1 124000 125000 3 0.00003 12 0.00012 indiv2
chr1 125000 126000 1 0.00001 6 0.00006 indiv2
chr1 126000 126000 2 0.00002 14 0.00014 indiv2
chr2 123000 124000 6 0.00006 20 0.00020 indiv2
chr2 124000 125000 0 0.00000 12 0.00012 indiv2
データを読み込む私のコード:
hetshoms <- read.table("fakedata.txt", header=F)
chrom <- hetshoms$V1
start.pos <- hetshoms$V2
end.pos <- hetshoms$V3
hets <- hetshoms$V4
het_stat <- hetshoms$V5
homs <- hetshoms$V6
hom_stat <- hetshoms$V7
indiv <- hetshoms$V8
HetRatio <- hets/(hets+homs)
qplot で染色体を別々にプロットしようとすると、うまくいきます。
testplot <- qplot(start.pos, HetRatio, facets = chrom ~ ., colour=chrom)
しかし、ggplot で類似のことを試してみると、うまくいきません。最初の部分は正常に動作します:
testplot <- ggplot(hetshoms, aes(x=start.pos, y=HetRatio)) + geom_point(aes(color=chrom))
しかし、facet_wrap を追加しようとすると:
testplot + facet_wrap(~chrom)
これにより、次のエラーが発生します
「エラー en layout_base(data, vars, drop = drop) : 少なくとも 1 つのレイヤーには、ファセットに使用されるすべての変数が含まれている必要があります」
(as.formula(paste)) を facet_wrap() に追加して、直接 hetshoms$V1 を呼び出してみましたが、どちらも問題を解決しません。
コードを修正する方法についての提案をいただければ幸いです。