2015-04-17 15 views
9

plot() işleviyle oluşturulan grafiğimde bir gösterge yapmak istiyorum. Orijinal legend() işlevi, yalnızca 1 sütuna sahip bir liste oluşturur. 2 sütun içeren bir efsaneyi nasıl yapabilirim?2 sütunlu R efsanesi nasıl yapılır?

Wanted legend

+0

'Ncol = 2' 'in legend'? – Victorp

+1

Ama satır başına sadece 1 metin etiketine ihtiyacım var –

+0

@FelixChan Satır başına bir Metin etiketi – RUser

cevap

8

Ben standart araziler için legend tek bir çağrı içinde bunu yapmak için bir yol bulamadı.

İki tane farklı efsane çizen bir seçenek var: bir tane çizgiler ve noktalar, bir tanesi etiketli. Etiket ve çizgiler arasındaki mesafeyi düzeltmek için x.intersp kullanılabilir.

plot(cumsum(runif(n = 100))) 

# draw legend with lines and point but without labels and box. x.intersp controls horizontal distance between lines 
L = legend(x = 'bottom', legend = rep(NA,4), col=1:2, lty=c(1,1,2,2), ncol=2, bty='n', x.intersp=0.5, pch=c(1,2,1,2), inset=0.02) 

# use position data of previous legend to draw legend with invisble lines and points but with labels and box. x.intersp controls distance between lines and labels 
legend(x = L$rect$left, y = L$rect$top, legend = c('Group A', 'Group B'), col=rep(NA,2), lty=c(1,1), ncol=1, x.intersp = 3, bg = NA) 

enter image description here

3

Kontrol bu:

library(lattice) 

myPCH <- 15:17 
Data <- rnorm(50) 
Index <- seq(length(Data)) 

xyplot(Data ~ Index, 
     pch = myPCH, col=1:2, 
     key = list(space = "right", adj=1, 
        text = list(c("a", "b", "c"), cex=1.5), 
        points = list(pch = myPCH), 
        points = list(pch = myPCH,col=2))) 

enter image description here

+0

Bence OP 2x2 satır + 2x1 dizgisi istiyor. –

+0

@Pascal Cevabı düzenledi – RUser

İlgili konular