I used the following code to produce a grouped boxplot
S<-read.table("N.csv", sep=";",header = TRUE)
S
D_Level Mel R FW
1: 100% 0 mM 1 60
2: 100% 0 mM 2 70
3: 100% 0 mM 3 64
4: 100% 50 mM 1 90
5: 100% 50 mM 2 85
6: 100% 50 mM 3 88
7: 100% 100 mM 1 80
8: 100% 100 mM 2 85
9: 100% 100 mM 3 75
10: 100% 200 mM 1 74
11: 100% 200 mM 2 68
12: 100% 200 mM 3 75
13: 70% 0 mM 1 62
14: 70% 0 mM 2 50
15: 70% 0 mM 3 58
16: 70% 50 mM 1 85
17: 70% 50 mM 2 80
18: 70% 50 mM 3 75
19: 70% 100 mM 1 67
20: 70% 100 mM 2 65
21: 70% 100 mM 3 60
22: 70% 200 mM 1 60
23: 70% 200 mM 2 68
24: 70% 200 mM 3 70
25: 50% 0 mM 1 56
26: 50% 0 mM 2 40
27: 50% 0 mM 3 46
28: 50% 50 mM 1 45
29: 50% 50 mM 2 53
30: 50% 50 mM 3 55
31: 50% 100 mM 1 50
32: 50% 100 mM 2 55
33: 50% 100 mM 3 50
34: 50% 200 mM 1 51
35: 50% 200 mM 2 50
36: 50% 200 mM 3 48
S$D_Level <- factor(S$D_Level,
levels = c('100%','70%','50%'),ordered = TRUE)
ggplot(data=S) +
geom_boxplot( aes(x=factor(D_Level), y=FW, fill=factor(Mel),order =
as.numeric(Mel)), position=position_dodge(.8)) +
theme(panel.background = element_rect(fill = 'white', colour = 'black'))+
labs(x = "Drought level",y = "FW",fill = "Mel")+
scale_fill_discrete(breaks=c("0 mM","50 mM","100 mM","200 mM"))
It works well as you see in this graph:
As you see, the boxes are in order: 0, 100, 200 and 50. But, I would like to make them in order: 0, 50, 100 and 200. Any help?