Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
899 views
in Technique[技术] by (71.8m points)

r - Extract statistics from boxplot

I've already tried searching but I've found nothing similar. I have a dataset containing temperatures, and another dataset containing 23 tipes of terrain (categorical variable). I have drawn a dataset of temperature versus type of terrain, seen a trend in this plot and now I want to extract statistics (i.e. median) from this plot.

This is the code I used for drawing the boxplot:

boxplot(zone$tm_03 ~ ds3_utm$terr, col='chartreuse3', xlab='Terreno', ylab='Temperatura (°C)', varwidth=T)

And this is the boxplot I found:

Boxplot

What I'd like to do is to extract from the boxplot the value of the median for each category. I thought of using boxplot.stats(), but I didn't manage to make it work.

boxplot_stats<-boxplot.stats(zone$tm_01 ~ ds3$terr)
Error in x[floor(d)] + x[ceiling(d)] : 
  non numeric argument transformed in binary operator
Inoltre: Warning messages:
1: In is.na(x) :
is.na() applied to non-(list or vector) of type 'language'
2: In is.na(x) :
is.na() applied to non-(list or vector) of type 'language'
3: In is.na(x) :
is.na() applied to non-(list or vector) of type 'language'

And summary():

> summary(boxplot(zone$tm_03 ~ ds3_utm$terr, col='chartreuse3', xlab='Terreno', ylab='Temperatura (°C)', main='Marzo', varwidth=T))
Errore in summary(boxplot(zone$tm_03 ~ ds3_utm$terr, col = "chartreuse3",  : 
  error in evaluating the argument 'object' in selecting a method for     function 'summary': Errore in eval(expr, envir, enclos) : oggetto "ds3_utm" not found.

Anyone can help me?

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From boxplot help:

Value

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 in your case, you can get the medians of the different categories this way:

# drawing the boxplots and assigning the results to an object
bp<-boxplot(zone$tm_03 ~ ds3_utm$terr, col='chartreuse3', xlab='Terreno', ylab='Temperatura (°C)', varwidth=T)
# get the different medians, which are on the 3rd row of the stats element
bp$stats[3,]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...