2017-02-07 7 views
0

I manuell bin eine Matrix wie folgt zu schaffen:Balkendiagramm in R manuell eingegebenen Matrixdaten unter Verwendung

A = matrix(
c("Dp10 WT", "Dp10 WT", "Dp10 WT", 
    "Dp10", "Dp10", "Dp10", 
    "Dp16 WT", "Dp16 WT", "Dp16 WT", 
    "Dp16", "Dp16", "Dp16", 
    121.36, 129.11, 149.46, 141.3, 129.11, 131.02, 
    0, 134.8, 144.5, 134.33, 129.11, 160.02), 
nrow=12, 
ncol=2, 
byrow = FALSE) 

Dann Umbenennungs Zeilen und Spalten und Umwandeln in Datenrahmen:

dimnames(A) = list(seq(1,12) 
,c('Sample', 'Concentration')) # column names 
DF=data.frame(A) 

Dann Plotten:

melted <- melt(DF, id.vars=c("Sample")) 
means <- ddply(melted, c("Sample"), summarise, mean=mean(value)) 
means.barplot <- qplot(x=group, y=mean, fill=group, data=means, geom="bar", stat="identity", position="dodge") 

Aber die ddply Linie mir die folgende Fehlermeldung geben:

argument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NA 

Was ist das Problem hier? Oder gibt es eine einfachere Möglichkeit, ein Balkendiagramm mit std dev als Fehlerbalken zu zeichnen?

Antwort

1

Die Concentration Daten sind in character Format.

Sie müssen es numeric ändern:

DF$Concentration <- as.numeric(DF$Concentration) 

Auch sollten Sie die Argumente von qplot (z x=group, da es keine Spalte group in means benannt ist) überprüfen.

Verwandte Themen