2016-05-04 23 views
1

Ich habe folgende Datensatz:ein boxplot Erstellen, ggplot2

depth <- data.frame(Sample = c("AD_001", "AD_009", "AD_017", "AD_025", 
          "AD_033", "AD_041", "AD_049", "AD_057", 
          "AD_065", "AD_073", "AD_081", "AD_089"), 
       median = c(12, 13, 11, 12, 12, 12, 13, 13, 14, 15, 15, 13), 
       granular_first_quartile = c(5, 6, 5, 6, 5, 6, 6, 6, 7, 7, 7, 6), 
       granular_third_quartile = c(23, 25, 21, 22, 23, 23, 24, 25, 27, 28, 28, 24)) 

und möchte eine boxplot schaffen, sondern, die Graphen ich Erzeugung nicht über eine ebenso getrennt x Feld.

ggplot(depth, aes(as.factor(Sample))) + geom_boxplot(aes(middle = median, lower = granular_first_quartile, upper = granular_third_quartile, ymin = granular_first_quartile, ymax = granular_third_quartile), stat = 'identity') + coord_flip() 

Danke für die Hilfe!

+1

das letzte Beispiel in '? geom_boxplot' zeigt Ihnen, wie Sie einen Boxplot aus Statistikzusammenfassungen erstellen können. Wie funktioniert http://stackoverflow.com/questions/22212885/producing-a-boxplot-in-gplot2-using-summary-statistics – rawr

+1

Ihre Daten haben nur einen Wert von Median pro Faktor Ebene in Sample. Wenn Sie ein Boxplot eines einzelnen Werts erstellen, gibt es nur eine Linie bei diesem Wert zurück, von der ich annehme, wie Ihre Plot aussieht - eine Linie mit dem Wert des Median für jede Sample-Ebene. Die Handlung wird keine Schnurrhaare haben. –

Antwort

2

Sie haben bereits alle (Median, Q1 und Q3) und müssen nur lower, upper, zuweisen middle, ymin und ymax

(FYI, https://en.wikipedia.org/wiki/Box_plot#/media/File:Boxplot_vs_PDF.svg)

ggplot(depth, aes(Sample, median)) + 
geom_boxplot(aes(lower = granular_first_quartile, upper = granular_third_quartile, 
middle = median, 
ymin = granular_first_quartile - 1.5*(granular_third_quartile-granular_first_quartile), 
ymax = granular_third_quartile+1.5*(granular_third_quartile-granular_first_quartile)), 
stat="identity")+ coord_flip() 
+1

große Antwort. Ich brauche die Whisker nicht, also setze ich ymin und ymax auf granular_first_quartile bzw. granular_third_quartile. Das einzige Problem, das ich habe, ist, dass die x-Achse nicht gleichmäßig verteilt ist. – Crt

+1

aber, wenn ich Ihre Antwort verwende, ist die x-Achse gleichmäßig verteilt. – Crt

Verwandte Themen