I\'m successfully using the boxplot
function to generate... boxplots. Now I need to generate tables containing the stats that boxplot
calculates in
Others have answered the specific question about the return object for the boxplot
function, I would just add that if you want to learn about return objects in general then you should really learn about lists and how to use the str
function which will generally give you a much more meaningful view of an object then what you show above. There is also the TkListView
function in the TeachingDemos
package that gives a more interactive exploration of list and other objects. Using str
and names
and subsetting (see help("[")) will let you get a feel for what is in a return object (the help page for the function that created the object is also a good place to start) and how to access the pieces you want.
If you really want quantiles of your data instead of boxplot numbers, using quantile
directly would be my choice (it is far easier to read if you look through what you did later).
quantile (x, probs = c (0, .25, .5,.75, 1))
quantile
itself does not work with groups, but you can combine it with aggregate
so it is called for each of the groups given in argument by
(needs to be a list, so you can combine here several grouping factors):
aggregate (chondro$x, by = list (chondro$clusters),
FUN = quantile, probs = c (0, .25, .5,.75, 1))
with the result:
Group.1 x.0% x.25% x.50% x.75% x.100%
1 matrix -11.55 -6.55 5.45 14.45 22.45
2 lacuna -11.55 -2.55 4.45 10.45 22.45
3 cell -8.55 -1.55 11.45 15.45 20.45
If you really want to have boxplot numbers (e.g. how far the whiskers go), have a look at ? fivenum
and ? boxplot.stats
.
boxplot
returns a structure in R called a list
.
A list is more-or-less a data container where you can refer to elements by name.
If you do A <- boxplot(...)
, you can access the names
with A$names
, the conf
with A$conf
, etc.
So, looking at the boxplot
helpfile ?boxplot
under Value:
(which tells you what boxplot
returns), we see that it returns a list with the following components:
stats: a matrix, each column contains the extreme of the lower
whisker, the lower hinge, the median, the upper hinge and the
extreme of the upper whisker for one group/plot. If all the
inputs have the same class attribute, so will this component.
n: a vector with the number of observations in each group.
conf: a matrix where each column contains the lower and upper
extremes of the notch.
out: the values of any data points which lie beyond the extremes
of the whiskers.
group: a vector of the same length as ‘out’ whose elements indicate
to which group the outlier belongs.
names: a vector of names for the groups.
So the table for each of the stats is in A$stats
, each column belongs to a group and contains the min, lower quartile, median, upper quartile, and max.
You could do:
A <- boxplot(...)
mytable <- A$stats
colnames(mytable)<-A$names
rownames(mytable)<-c('min','lower quartile','median','upper quartile','max')
mytable
which returns (for mytable
):
U UM M LM L
min 178.9983 216.5999 189.8641 209.4726 202.0571
lower quartile 182.2274 217.0550 201.8764 209.5265 207.3756
median 202.1085 228.5095 219.5254 214.7852 220.0937
upper quartile 220.3754 267.0707 234.2601 230.0274 226.2467
max 221.9904 284.8324 279.3434 240.0647 240.3436
Then you can refer to it like mytable['min','U']
.