2
私はプロットオブジェクトに変換された2つのggplotオブジェクトを手配し、共通の凡例を1つ使用しようとしています。しかし、伝説は何とか倍増さ:2つのggplotと共通の凡例をプロットしたサブプロット?
df1 <- read.table(text = "group x y
group1 -0.212201 0.358867
group2 -0.279756 -0.126194
group3 0.186860 -0.203273
group4 0.417117 -0.002592
group1 -0.212201 0.358867
group2 -0.279756 -0.126194
group3 0.186860 -0.203273
group4 0.186860 -0.203273", header = TRUE)
df2 <- read.table(text = "group x y
group1 0.211826 -0.306214
group2 -0.072626 0.104988
group3 -0.072626 0.104988
group4 -0.072626 0.104988
group1 0.211826 -0.306214
group2 -0.072626 0.104988
group3 -0.072626 0.104988
group4 -0.072626 0.104988", header = TRUE)
library(dplyr)
library(ggplot2)
library(plotly)
p1 <- ggplot(df1, aes(x = x, y = y, colour = group)) +
geom_point(position = position_jitter(w = 0.04, h = 0.02), size = 1.8)
p2 <- ggplot(df2, aes(x = x, y = y, colour = group)) +
geom_point(position = position_jitter(w = 0.04, h = 0.02), size = 1.8)
subplot(ggplotly(p1), ggplotly(p2), nrows = 1)
私は
subplot(ggplotly(p1), ggplotly(p2), nrows = 1) %>% layout(showlegend = FALSE)
を試みたが、全体の伝説はちょうど私が2つとダブル伝説を修正することができませんでした
感謝。リージョンが選択されているとき、両方のプロットで同じリージョンを選択する方法を知っていますか? – schlusie
x軸とy軸の範囲を同じにしたいのですか?そうであれば、いくつかのオプションがあります。 (1) 'scales =" free "を削除します。 (2) 'facet_wrap(〜df、scales =" free ")+'を 'facet_grid(。〜df)+'に置き換えます。 (3) 'scale_y_continuous(limits = c(-0.2,0.3))'などの範囲を手動で設定し、同様にx軸に対して範囲を設定します。 (4) 'coord_cartesian(xlim = c(-0.3、0.4)、ylim = c(-0.2、0.4))'で範囲を手動で設定します。 – eipi10
ありがとうございます。しかし私が望んだことは、陰謀のオブジェクトにあります:私は矩形または特定の領域を描くことによってズームインすることができます。選択したプロットの軸だけが適応します。しかし、私は両方の軸を適応させたい。 – schlusie