見出し画像

凡例(レジェンド)を消す

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")

下記のような画像が出力されます。

凡例を非表示にしたボックスプロット


この記事が気に入ったらサポートをしてみませんか?