R/plothist.R

#'@title histogram of data
#'
#'@description Get a histogram, showing the mean and median of your data
#'@author Oscar Ramirez Alan (\email{osoramirez@@gmail.com}).
#'@param x is a numeric value, could be a  a vector or data.frame
#'@export plothist
#'@keywords plothist
#'@return a summary
#'@export plothist
#'@import "graphics","stats"
#'@examples
#'x<-rnorm(25,2,3)
#'plothist(x)
#'
#'
plothist <- function(x) {
  opar <- par(no.readonly = TRUE)
  on.exit(par(opar))
  par(mfrow=c(1,1))
  xlab <- deparse(substitute(x))  # get the expression passed as y
  hist(x, main=paste("Histogram of",  xlab), col = "#EBEBEB", xlab = "", cex=.9)
  abline(v = mean(x), lwd = 3, col="red")
  abline(v = median(x), col = "#3F689E", lwd = 2.5,lty=2)
  legend(x = "topright", pch = 1, title = "Legend",box.lty=0,cex=.7,bg="transparent",
         c("Mean", "Median"),
         col = c( "red", "#3F689E"),
         lwd = c(2, 2), lty=c(1,2))
  Max <- round(max(x), 3)
  Stdev <- round(sd(x, na.rm = TRUE), 3)
  Mean <- round(mean(x, na.rm = TRUE), 3)
  Median <- round(median(x, na.rm = TRUE), 3)
  n <- length(x)
cat(paste("This option performs a histogram that show "))
   {
     cat(paste("your data has mean of ", Mean,  " and ", Stdev, " of standar desviation. "))
  }
{
  cat(paste("Your median is ", Median, " in ", n, " samples data. "))
}
cat(paste("Check all your statistical data, using function: resume2data."))
}
osoramirez/resumeRdesc documentation built on May 31, 2019, 5:13 p.m.