2017-08-05 13 views
1

Ich versuche, eine boxplot mit GGplot zu tun, und ich bekomme nur eine Box, wenn ich eine ggplot tun wieGGplot Boxplot vs boxplot

ggplot(data_frame, aes(x=probs, y=values)) + 
    geom_boxplot(color="red", fill="orange", alpha=0.5) 

während ich 3 Boxen bekommen werden soll, wenn ich die normale Handlung tun:

boxplot(values ~ probs, data = data_frame, 
     xlab = "Probabilities", 
     ylab = "Values (1Q, Mean, Median, StdDev, 3Q)", 
     main = "1Q, Mean, Median, StdDev, 3Q", 
     col = c("green","yellow","purple")) 

Sample data: 
> head(data_frame,20) 
    values probs 
1 16.000 0.3 
2 18.000 0.3 
3 18.000 0.3 
4 3.550 0.3 
5 20.000 0.3 
6 27.000 0.5 
7 30.000 0.5 
8 30.000 0.5 
9 3.873 0.5 
10 33.000 0.5 
11 46.000 0.8 
12 48.000 0.8 
13 48.000 0.8 
14 3.098 0.8 
15 50.000 0.8 

Alle Zeiger wird sehr geschätzt. Danke!

Antwort

0

Die X-Achse von Geom_boxplot muss so kategorisiert sein, dass sie wie gewünscht aussieht. Eine Lösung ist, zu transformieren "Probs" als Zeichen:

ggplot(data_frame, aes(x=as.character(probs), y=values)) + 
    geom_boxplot(color="red", fill="orange", alpha=0.5) 
0

Hoffentlich ist das, was Sie suchen ...

ggplot(df, aes(x=factor(probs), y=values)) + 
    geom_boxplot(color="red", fill="orange", alpha=0.5)