about orders of the objects in boxplot

18 views
Skip to first unread message

lily li

unread,
Sep 28, 2016, 12:50:05 PM9/28/16
to ggp...@googlegroups.com
Hi ggplot users,

I have a dataframe,
> df1
     id month  A  B  C
1   ben     1 65 21 54
2   ben     2 66 23 55
3   ben     3 54 24 56
4  cort     4 44 23 53
5  cort     5 67 22 52
6  cort     6 66 21 50
7   jam     1 45 20 51
8   jam     2 56 19 57
9   art     1 40 25 58
10  art     2 39 24 53
11  art     6 56 19 54
12  art     7 55 20 52
13  art     8 67 21 50

I want to draw a boxplot for column A. My code is like this:
df1 = read.csv('~/Desktop/data1.csv',header=T)
boxplot1 = ggplot(data=df1,aes(x=factor(id),y=A))+geom_boxplot()
show(boxplot1)

In the figure, the objects on the x-axis appear alphabetically, which means that they appear in the order: art, ben, cort, jam. How to remove the order? I want the objects to appear according to the order in the original dataset: ben, cort, jam, art. Thanks for your help.

Roman Luštrik

unread,
Sep 28, 2016, 12:53:27 PM9/28/16
to lily li, ggp...@googlegroups.com
You need to change the order of factor levels in your data.frame.


Cheers,
Roman

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.
Reply all
Reply to author
Forward
0 new messages