Add statistical information at the bottom of the graph

I am trying to add statistical information (min, max, quartile values, average, median, etc.) regarding a given distribution at the bottom of the graph (histogram, time series graph) in R. I know that statistics can be generated using summary () functions. However, you do not know how to place such information at the bottom of the chart?

It seems like this should be easy to do, but I just can't find anything on the Internet regarding how to do this. Is it even possible to use R?

Any help would be greatly appreciated!

+7
source share
1 answer

Here is one way. For some dummy data

set.seed(2) dat <- rnorm(100, mean = 3, sd = 3) 

calculate resume

 sdat <- summary(dat) 

Then we can paste the names of the summary statistics and their values ​​with paste() , and collapse one line

 summStr <- paste(names(sdat), format(sdat, digits = 2), collapse = "; ") 

Note that I am formatting statistics values ​​to have only two significant digits using format() . This can be added to the plot as subtitles using the title() function

 op <- par(mar = c(7,4,4,2) + 0.1) hist(dat) title(sub = summStr, line = 5.5) par(op) 

I am pushing subtitles on the chart a bit through the line argument.

text added to a plot as a subtitle

+10
source

All Articles