Ich möchte meine Daten vom Wide- in das Long-Format umformen, so dass ich mit ggplot Graphen erstellen kann. Ich habe einige Probleme, um die Daten richtig zu arragnetieren. Bisher beginne ich meinen Prozess mit einer Liste von 27 Datenrahmen (nur die ersten 10 Einsen angezeigt):Datenframeformat für ggplot anordnen - R
> str(NDVI_stat)
List of 27
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 1 mean: num [1:10] 0.1796 0.3105 0.1422 0.0937 0.1711 ...
..$ NDVI 1 sd : num [1:10] 0.1117 0.05845 0.00743 0.02754 0.01506 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 2 mean: num [1:10] 0.0819 0.5954 0.1328 0.0953 0.1492 ...
..$ NDVI 2 sd : num [1:10] 0.00872 0.10508 0.00863 0.01878 0.02303 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 3 mean: num [1:10] 0.0634 0.681 0.2108 0.0151 0.179 ...
..$ NDVI 3 sd : num [1:10] 0.0344 0.076 0.0361 0.0638 0.0428 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 4 mean: num [1:10] 0.0971 0.6885 0.2326 0.1157 0.3219 ...
..$ NDVI 4 sd : num [1:10] 0.00991 0.07509 0.02054 0.02793 0.0303 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 5 mean: num [1:10] 0.0817 0.4825 0.2754 0.1003 0.4155 ...
..$ NDVI 5 sd : num [1:10] 0.00998 0.05034 0.02781 0.03248 0.04056 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 6 mean: num [1:10] 0.1119 0.7667 0.582 0.0997 0.4426 ...
..$ NDVI 6 sd : num [1:10] 0.023 0.0672 0.0649 0.0331 0.0557 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 7 mean: num [1:10] 0.1997 0.6567 0.5111 0.0988 0.3307 ...
..$ NDVI 7 sd : num [1:10] 0.0671 0.0756 0.0435 0.0288 0.0457 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 8 mean: num [1:10] 0.3626 0.7356 0.6304 0.0954 0.335 ...
..$ NDVI 8 sd : num [1:10] 0.1454 0.0888 0.0502 0.0298 0.038 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 9 mean: num [1:10] 0.541 0.748 0.637 0.089 0.577 ...
..$ NDVI 9 sd : num [1:10] 0.0968 0.0721 0.0396 0.0276 0.0656 ...
$ :'data.frame': 10 obs. of 2 variables:
..$ NDVI 10 mean: num [1:10] 0.6691 0.4377 0.6713 0.0942 0.6827 ...
..$ NDVI 10 sd : num [1:10] 0.088 0.0698 0.033 0.0316 0.0688 ...
$ :'data.frame': 10 obs. of 2 variables:
Ich verwende rbindlist
vom data.table package
alles in einem einzigen dataframe
newdf<-rbindlist(NDVI_stat, use.names = TRUE, fill = TRUE)
Der Code funktioniert ordnungsgemäß, aber ich erstelle nicht die Struktur, die ich wirklich brauche. Der Ausgang ist ein dataframe
mit 270 (27 daframes * 10 Zeilen in jeder) Beobachtungen und 54 Variablen (27 Datenrahmen * 2 Spalten in jedem)
Wie Sie im Bild sehen können newdf
es ist Erstellen von 270 Zeilen, aber was ich erhalten möchte, ist 10 Zeilen (also vermeiden Sie die NA-Werte)
Irgendwelche Hilfe dazu?
Diese Frage ist ähnlich wie diese Plot dataframe with ggplot2 - R
Der Unterschied ist, dass ich die Art und Weise änderte ich meine Eingabe produziert und weiß, ich weiß nicht, wie der Datenrahmen richtig später arrangieren verwenden
NDVIdf_forplot <- gather(NDVIdf, key = statistic, value = value, -ID)
und dann mit ggplot mein Diagramm erstellen
Irgendwelche Hilfe dazu?
Vielen Dank, es löste mein Problem – GCGM