2017-11-09 25 views
2

塗りつぶしと形状の美しさを使ってプロットを作成しようとしています。プロットは素晴らしく見えますが、伝説は塗りつぶしの美学によって色づけされません。これを整理するのを手伝ってもらえますか?ここでR:ggplotプロットの凡例での形状と塗りつぶしの不一致

のコード例今

#Example dataset 
bio_rep = rep(c(1:3), 4) 
category = rep(c("w", "x", "y", "z"), each = 3) 
ranking = sample(c("s","a","b","c"), 12, replace = T) 
score = runif(12) 

df = data.frame(bio_rep, category, ranking, score) 

> df 
    bio_rep category ranking  score 
1  1  w  b 0.12496463 
2  2  w  b 0.82229942 
3  3  w  b 0.20121351 
4  1  x  a 0.06352934 
5  2  x  s 0.57510752 
6  3  x  a 0.54471793 
7  1  y  a 0.87203684 
8  2  y  c 0.32858945 
9  3  y  a 0.06234144 
10  1  z  c 0.41124401 
11  2  z  s 0.62253128 
12  3  z  a 0.42499771 

プロット

require(ggplot2) 

ggplot(df, aes(category, score, shape = factor(bio_rep), fill = ranking))+ 
    geom_point(size = 3)+ 
    scale_shape_manual(values = c(21,22,23)) 

あなたが見ることができるように、は伝説に着色されませんランキングは

Image link here!

ドゥあなたはどのように知っているそれを解決する?事前 で

多くのおかげでMP

答えて

3

理由は「ランキング」の伝説が使用するデフォルトの形状はfill美的(のみcolor)を持っていないということです。あなたはoverride.aesを使用して、他の凡例のものと一致し、この形状を変更することができます。

ggplot(df, aes(category, score, shape = factor(bio_rep), fill = ranking))+ 
    geom_point(size = 3)+ 
    scale_shape_manual(values = c(21,22,23)) + 
    guides(fill = guide_legend(override.aes = list(shape=21))) 

enter image description here

+0

タールが驚くほど速く答えた:あなたの助けのアルテム用O感謝! :) –

関連する問題