2017-02-14 3 views
0

の不正な伝説:Rベースプロット機能:私はプロット伝説の困難が午前グラフ

head(bee.ground) 
    X Month Treatment Block Bee_Richness Bee_Abundance Bare Grass Forb Dead Moss 
1 1 May  DS  1   0    0 23.20 15.72 37.80 17.00 0 
2 2 May  GS  1   0    0 33.52 21.88 33.60 9.88 0 
3 3 May  UB  1   1    1 0.60 18.28 35.00 43.48 0 
4 4 May  DS  2   7   71 11.20 11.20 58.80 16.68 0 
5 5 May  GS  2   5    6 37.00 12.08 43.92 5.12 0 
6 6 May  UB  2   5   16 4.40 14.88 12.32 67.88 0 

    shape<-as.numeric(as.factor(bee.ground$Block)) 
    color<-as.numeric(as.factor(bee.ground$Treatment)) 

    plot(bee.ground$Bare, bee.ground$Bee_Richness, main = "Bee Richness and Bare Ground Cover", 
xlab = "Percent Bare Ground", ylab = "Bee Richness", 
pch = shape, 
col = color, 
las = 1, 
cex = 1.5) 

test graph

これは私がもらう素敵なグラフであり、私は黒がDSだと思います、赤はGS、緑はUBです。ブロック(4つの異なる形)も正しいと思われる。私はこれらの同じパラメータで伝説を作る際 はしかし、私はこれを取得:legend's in the top corner...

legend("topleft", 
    pch = shape, 
    col = color, 
    legend = c("Block 1","Block 2","Block 3","Block 4", NA, "DS","GS","UB")) 

それはやっているすべての色を交互に形状を3回繰り返し、代わりにどのような(と思う)でグラフを一致さ表示されます。私はマージ機能を試しましたが、それは問題を修正しませんでした(同じ誤った凡例を生成します)。

〜グラフの下に凡例を配置して中央に配置する方法もありますか?編集:私はこれを考え出した! ylimを-3に調整し、水平の凡例のためのスペースを残しました。

〜多分別のものです。最初のいくつかのオプションだけを使用する代わりに、どのように特定の色を指定し、それぞれの特定のシェイプをブロックするにはどうすればよいですか?

ありがとうございました!

EDIT:ブロックと治療を区別する2つの別個の伝説を作り上げました。

shape <- ifelse(bee.ground$Block == "1", 1,ifelse(bee.ground$Block == "2", 2, ifelse(bee.ground$Block == "3",3,4))) 
color <- ifelse(bee.ground$Treatment == "DS", 'red',ifelse(bee.ground$Treatment == "GS", 'green', 'black')) 

plot(bee.ground$Bare, bee.ground$Bee_Richness, main = "Bee Richness and Bare Ground Cover", 
    xlab = "Percent Bare Ground", ylab = "Bee Richness",pch = c(shape), 
    col = c(color),las = 1,cex = 1.5,ylim = c(0,35)) 
legend("topleft", c('1','2','3','4'),pch = c(1,2,3,4),horiz = TRUE,title = "Block") 
legend("topright",c("DS","GS","UB"),horiz = TRUE, text.col = c("red","green","black"),title = "Treatment",title.col = "black") 

答えて

0

これはおそらく役立ちます。私はplotlegendのために私が欲しかった形と色を指定しました。

shape <- as.numeric(as.factor(bee.ground$Block)) 
color <- as.numeric(as.factor(bee.ground$Treatment)) 

plot(bee.ground$Bare, bee.ground$Bee_Richness, 
    main = "Bee Richness and Bare Ground Cover", 
    xlab = "Percent Bare Ground", ylab = "Bee Richness", 
    pch = shape, col = color, las = 1, cex = 1.5) 

    legend("topleft", c('Block DS, Treatment 1', 
         'Block DS, Treatment 2', 
         'Block DS, Treatment 3', 
         'Block GS, Treatment 1', 
         'Block GS, Treatment 2', 
         'Block GS, Treatment 3', 
         'Block UB, Treatment 1', 
         'Block UB, Treatment 2', 
         'Block UB, Treatment 3'), 
         pch = c(1,1,1,2,2,2,3,3,3), 
         col = c('blue', 'green', 'brown', 
           'blue', 'green', 'brown', 
           'blue', 'green', 'brown')) 


shape <- ifelse(bee.ground$Block == 'DS', 3, 
     ifelse(bee.ground$Block == 'GS', 6, 9)) 

color <- ifelse(bee.ground$Treatment == 1, 'red', 
     ifelse(bee.ground$Treatment == 2, 'blue', 'black')) 

plot(bee.ground$Bare, bee.ground$Bee_Richness, 
    main = "Bee Richness and Bare Ground Cover", 
    xlab = "Percent Bare Ground", ylab = "Bee Richness", 
    pch = shape, col = color, las = 1, cex = 1.5) 

    legend("topleft", c('Block DS, Treatment 1', 
         'Block DS, Treatment 2', 
         'Block DS, Treatment 3', 
         'Block GS, Treatment 1', 
         'Block GS, Treatment 2', 
         'Block GS, Treatment 3', 
         'Block UB, Treatment 1', 
         'Block UB, Treatment 2', 
         'Block UB, Treatment 3'), 
         pch = c(3,3,3,6,6,6,9,9,9), 
         col = c('red', 'blue', 'black', 
           'red', 'blue', 'black', 
           'red', 'blue', 'black')) 
+0

ありがとうございます!私は元の投稿にいくつかの編集を入れました:) – Brenna