ggplot2 を使用して 2 つの個別の散布図を作成しましたが、それらを 1 つの単一のプロットに結合する必要があります。各プロットは、3 つの異なる処理 (背景) の下にあるトカゲの集団を対象としています。各プロットについて、次のものがあります。
csMS = data.frame()
ellMS = data.frame()
centroidsMS = data.frame()
csplotMS = ggplot(csMS, aes(x = RG, y = GB, colour = Background)) + geom_point(size = 3, shape = 17) + #colour by background, circles size 3
geom_path(data = ell.AS, aes(x = RG, y = GB ,colour = Background), size = 1, linetype = 2) + #adding the ellipses
geom_point(data = centroidsMS, size = 3, shape = 17) + #added centroids
geom_errorbar(data = centroidsMS, aes(ymin = GB - se.GB, ymax = GB + se.GB), width = 0) + #add y error bars
geom_errorbarh(data = centroidsMS, aes(xmin = RG - se.RG, xmax = RG + se.RG), height = 0) +
theme_bw() + #white background
theme(axis.title.y = element_text(vjust = 2), axis.title.x = element_text(vjust = -0.3)) + #distance of axis titles from axis
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), #no grids
axis.line = element_line(colour = "black")) + #black axes
theme(text = element_text(size = 30)) + #font size
ylab("(G-B)/(G+B)") + xlab("(R-G)/(R+G)") + # Set text for axes labels
scale_colour_manual(values = c("black","#FF6600", "yellow1")) + #changed default colours
labs(colour = "Murray Sunset NP") +
theme(legend.title = element_text(size = "20")) + #changes the legend title
theme(legend.text = element_text(size = "20")) + #changes the legend title
theme(legend.key = element_blank()) + #removed little squares around legend symbols
theme(legend.direction = "horizontal", legend.position = c(.5, .85))
私は試した
csASMS = csplotAS + csplotMS
しかし、次のエラー メッセージが表示されます。
私も試しました
csASMS = grid.arrange(csplotAS, csplotMS)
しかし、これは一方のプロットをもう一方の上に配置しますが、両方のプロットを組み合わせて、基本的には 1 つのプロットだけにする必要がありますが、各プロットには異なるトカゲの個体数を示すための異なる規則があるため、2 つの個別の凡例があります。
どんな助けでも大歓迎です。
****編集**** 2014 年 12 月 12 日
2 つのプロットを 1 つにまとめることができましたが、まだ別々の凡例の問題があります。質問を単純化するために、cdeterman の要求に従って、いくつかのサンプル データを使用して、より単純な形式のコードを追加しています。
data frames: p1 and p2
> p1
treatment x y
1 Black 1 1
2 Orange 2 2
3 Yellow 3 3
> p2
treatment x y
1 Black 4 4
2 Orange 5 5
3 Yellow 6 6
次のコードを使用して、両方のデータ フレームを含むプロットを作成しました。
plot = ggplot(p1, aes(x = x, y = y, colour = treatment)) + geom_point(size = 3) + #colour by background, circles size 3
theme_bw() + #white background
theme(axis.title.y = element_text(vjust = 2), axis.title.x = element_text(vjust = -0.3)) + #distance of axis titles from axis
theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), #no grids
axis.line = element_line(colour = "black")) + #black axes
theme(text = element_text(size = 30)) + #font size
scale_colour_manual(values = c("black","#FF6600", "yellow1")) + #changed default colours
labs(colour = "p1") +
theme(legend.title = element_text(size = "20")) + #changes the legend title
theme(legend.text = element_text(size = "20")) + #changes the legend title
theme(legend.key = element_blank()) + #removed little squares around legend symbols
theme(legend.direction = "horizontal", legend.position = c(.33, 1)) +
# Now to add the second plot/ No need to code for axis titles, titles positions,etc b/c it's already coded in the first plot
geom_point(data = p2, aes(x = x, y = y, colour = treatment), size = 3, shape = 17)
これにより、各データ フレームが異なるシンボル (p1 の円と p2 の三角形) で表されるグラフが生成されますが、円の上に三角形が重ねられた組み合わせの凡例は 1 つだけです)。データ フレームごとに 1 つずつ、2 つの個別の凡例を取得するにはどうすればよいですか?
ありがとうございました!