2017-12-05 3 views
-1

Ich bin versuchen, Gruppe eine grafische Darstellung whith bedeutet Linien zu tun (in ggplot), und ich habe meinen Code wie dieseWie setzt man mittlere Linien in ggplot?

ggplot(gama, aes(x = distancia, y= glipidoscmtejido, colour= estado)) + 
geom_point(position=position_dodge(.5), alpha= 1, size=3) + 
geom_crossbar(data=gama,aes(x=distancia,ymin=mean(glipidoscmtejido), 
ymax=mean(glipidoscmtejido),y=mean(glipidoscmtejido),colour=estado), width = 0.5) 

und ich diese

enter image description here

, aber ich brauche die mittlere Linie von Distancia und von Estado. Wie kann ich es schaffen?

danke.

Antwort

0

Wie wäre es damit stat_summary mit den Mitteln plotten pro estado pro distancia:

# Generate some sample data 
set.seed(2017); 
df <- cbind.data.frame(
    x = rnorm(100), 
    estado = sample(c("sana", "lesionada"), 100, replace = T), 
    distancia = sample(c("0-1", "2.5-3.5", "5.6"), 100, replace = T)); 

require(ggplot2); 
ggplot(df, aes(x = distancia, y = x, colour = estado)) + 
    geom_point(position = position_dodge(width = 0.3)) + 
    stat_summary(
     fun.y = mean, 
     geom = "errorbar", 
     aes(ymax = ..y.., ymin = ..y..), 
     position = position_dodge(width = 0.3), 
     width = 0.25); 

enter image description here

+0

ist es möglich, die Länge der Leitung zu reduzieren? –

+0

@ victorpiñon Sie können die Breite des Balkens z. 'width = 0.25', siehe meine aktualisierte Lösung. –

+0

Es ist perfekt, vielen Dank –

Verwandte Themen