简体   繁体   中英

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 (ie 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:

箱形图

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!

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,]

Try the following:

res <-  boxplot(len ~ dose, data = ToothGrowth)
res

giving:

$stats
      [,1]  [,2]  [,3]
[1,]  4.20 13.60 18.50
[2,]  7.15 16.00 23.45
[3,]  9.85 19.25 25.95
[4,] 13.00 23.45 28.35
[5,] 21.50 27.30 33.90

$n
[1] 20 20 20

$conf
          [,1]     [,2]     [,3]
[1,]  7.783202 16.61792 24.21884
[2,] 11.916798 21.88208 27.68116

$out
numeric(0)

$group
numeric(0)

$names
[1] "0.5" "1"   "2"  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM