So schmelzen Sie R data.frame und Diagrammgruppe nach Balkendiagramm

Ich habe folgende R data.frame:

  group match unmatch unmatch_active match_active
1   A    10       4              0            0
2   B   116      20              0            3
3   c   160      27              1            4
4   D    79      17              0            3
5   E   309      84              4           14
6   F   643     244             10           23
...

Mein Ziel ist es, eine Gruppe nach Balkendiagramm zu zeichnen http: //www.cookbook-r.com/Graphs/Bar_and_line_graphs_ (ggplot2) / section-Graphs mit mehr Variablen) wie im Link gezeigt.

Ich merke, dass ich die Daten in das folgende Format bringen muss, bevor ich dazu komme

  group variable value
1   A    match    10
2   B    match   116
3   C    match   160
4   D    match    79
5   E    match   309
6   F    match   643
7   A    unmatch   4
8   B    unmatch  20
...

Ich habe die Schmelzfunktion benutzt:

groups.df.melt <- melt(groups.df[,c('group','match','unmatch', 'unmatch_active', 'match_active')],id.vars = 1)

Ich glaube nicht, dass ich das Schmelzen richtig mache, weil, nachdem ich die obigen Gruppen ausgeführt habe... Schmelz hat mehr als 1000 Zeilen, was für mich keinen Sinn ergibt.

Ich sah, wie Zeichne Histogramme pro Zeile über mehrere Spalten in R und habe versucht, dasselbe zu befolgen, aber ich erhalte nicht die gewünschte Grafik.

Außerdem erhalte ich folgende Fehlermeldung: Wenn ich versuche, das Plotten durchzuführen:

ggplot(groups.df.melt, aes(x='group', y=value)) + geom_bar(aes(fill = variable), position="dodge") + scale_y_log10()

Mapping a variable to y and also using stat="bin".
  With stat="bin", it will attempt to set the y value to the count of cases in each group.
  This can result in unexpected behavior and will not be allowed in a future version of ggplot2.
  If you want y to represent counts of cases, use stat="bin" and don't map a variable to y.
  If you want y to represent values in the data, use stat="identity".
  See ?geom_bar for examples. (Deprecated; last used in version 0.9.2)
Error in pmin(y, 0) : object 'y' not found

Antworten auf die Frage(1)

Ihre Antwort auf die Frage