![見出し画像](https://assets.st-note.com/production/uploads/images/128881641/rectangle_large_type_2_57eab1319641a61b22ae575b6a767810.png?width=800)
ggplot2: y = x の補助線を引く
下記のような散布図があったとします。このうち、変動していない遺伝子は、normal (x軸)と tumor (y軸) の値が同じ、つまり、 y = x になっている点ということです。これを判断しやすいように、 y = x の補助線を引く例を紹介します。
![scatter_plot](https://assets.st-note.com/img/1706278388049-YjySAKW9JL.png?width=800)
geom_abline() で直線を追加
y = x の直線を追加するには、 geom_point() にプラスで続けて、 geom_abline() を追加します。
g + geom_point(color = "#969696") +
geom_abline(slope = 1, intercept = 0)
引数として、傾き (slope) = 1 を、切片 (intercept) = 1 を指定しています。これで、y = x の直線が追加されます。
![scatter_plot_with_line](https://assets.st-note.com/img/1706279201764-2NtGK3pRxq.png?width=800)
続けて指定すれば、複数の線を追加可能です。 y = x + 1, y = x, y = x - 1 の3本を追加しています。
g + geom_point(color = "#969696") +
geom_abline(intercept = 1, linetype = "dotted", color = "red") +
geom_abline(intercept = 0, linetype = "dotted") +
geom_abline(intercept = -1, linetype = "dotted", color = "blue")
![scatter_plot_with_lines](https://assets.st-note.com/img/1706279481628-VxsnFQiaUs.png?width=800)
この記事が気に入ったらサポートをしてみませんか?