Boxplot in R statistical package


Plotting a boxplot for many groups in desired order


1. Create a file (example.txt) in the format:

group     value
a           1
a           2
b           5
c           10
a           2
b           6
c           11

2. Start R and do:

file=read.table(“example.txt”, header=T);



Look for additional parameters for boxplot in R documentation.

This works, but you may want to order your boxes in a different way. If you look online, many people will say that simply doing

group <- factor(group, levels=c(“c”, “a”, “b”))

will work.

It didn’t work for me.

What works is:

mat$group <- factor(as.character(mat$group), levels=c(“c”, “a”, “b”))



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s