2015-09-28 49 views
5

ggplot2でポイントの凡例の背景色を変更する方法を知っている人はいませんか?私は下のプロットを作成し、伝説の白い背景を変更したいと思いますか?何か案は?ggplot2の凡例の背景色を変更するには?

enter image description here

+2

は(legend.key = element_rect()= "黒" を埋める)、 '' +テーマを追加しますあなたの電話に – jeremycg

+0

ありがとうJeremycg – wilsonm2

答えて

8

あなたはthemelegend.keyパラメータを使用することができます。すなわち、例えば

theme(legend.key = element_rect(fill = "black"))

ある:

a <- seq(1:5) 
b <- seq(1:5) 
c <- seq(1:5) 
d <- data.frame(a, b, c) 
ggplot(data = d, aes(x = a, y = b, color = factor(c))) + 
    geom_point() + 
    theme(legend.key = element_rect(fill = "yellow")) 

が生成:

enter image description here

+0

素早く応答してくれてありがとう! – wilsonm2

関連する問題