あなただけの別のfonctionを追加したい場合は、別のレイヤーを追加:あなたは別のデータフレームからのデータを追加したい場合は+ geom_smooth()
ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(method = "lm", formula = y ~ splines::bs(x, 3), se = T) +
geom_smooth(method = "lm", formula = y ~ splines::bs(x, 4), se = T)
を、geom_smooth
内df
情報を追加:
ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(method = "lm", formula = y ~ splines::bs(x, 3), se = T) +
geom_smooth(data = mpg, aes(x = displ, y = cyl), method = "lm", formula = y ~ splines::bs(x, 4), se = T)
最後に、色や伝説をカスタマイズ: color
引数は `gridExtra :: grid.arrange`の凡例
ggplot(mpg, aes(displ, hwy)) + geom_point() +
geom_smooth(aes(color = "B"),method = "lm", formula = y ~ splines::bs(x, 3), se = T) +
geom_smooth(data = mpg, aes(x = displ, y = cyl, color = "A"), method = "lm", formula = y ~ splines::bs(x, 4), se = T) +
scale_color_manual("Legend Title", values = c("A" = "red", "B" = "blue"))
見た目に表示されるように
aes
内である必要がありますファセットを作ろうとすると、それは単一の凡例を使ってよりスケーリングされたプロットを与えます – TheRimalaya私は同じ座標系でプロットされた関数を持っていたい、 1ページに2つのプロットはありません。 – Lanza
別の要素を追加したい場合は、次のレイヤーを追加してください: '+ geom_smooth()' 例: 'ggplot(mpg、aes(displ、hwy))+ geom_point()+ geom_smooth(method =" lm "式= y〜splines :: bs(x、3)、se = T)+ geom_smooth(メソッド= "lm"、式= y〜スプライン:: bs(x、4)、se = T) ' – bVa