![見出し画像](https://assets.st-note.com/production/uploads/images/110715679/rectangle_large_type_2_d71c74f9c85fca400c5c2f18eb65473a.png?width=1200)
凡例(レジェンド)を消す
ggplot2 で作成した画像から、凡例(レジェンド)を消す方法です。
legend.position を指定
ggplot2 でボックスプロットを作成し、色付けすると、自動的に凡例(レジェンド)も表示されるようになります。この凡例が不要な場合は、theme()関数を使って、非表示にできます。下記のように、geom_boxplot() に + で、theme()関数を追加し、その中の legend.position に "none" を指定するとよいです。
theme(legend.position = "none")
plot_data <- input_data %>%
gather(Sample1, Sample2, key = "sample", value = "read_count")
ggplot(plot_data, aes(x = sample, y = read_count, fill = sample)) +
geom_boxplot() + theme(legend.position = "none")
下記のような画像が出力されます。
![](https://assets.st-note.com/img/1689259335524-SxQVASPwQH.png?width=1200)