y_hist: Histogram and density plot.

View source: R/y_hist.R

y_histR Documentation

Histogram and density plot.

Description

The function y_hist() creates a histogram and a density plot for a continuous variable.

The functions y_acf() and y_pacf() plot the autocorrolation and partial autocorrolation functions for y.

The function y_dots() is design for long tail right skewed variables. It is a plot emphasising the right tail of the distribution for such variables.

Usage

y_hist(y, data, with.density = TRUE, hist.col = "black",
         hist.fill = "white", dens.fill = "#FF6666", 
         binwidth = (max(y)-min(y))/20,  from, to, title)
         
y_acf(x, data, title)

y_pacf(x, data, title)

y_dots(y, data, value=3, point.size = 2, point.col = "gray", 
          quantile = c(.10, .50, .90),
          line.col = c("black","red", "black"),
          line.type = c("dotted", "solid",  "dotted"),
          line.size = c(1,1,1), x.axis.col = "black", 
          x.axis.line.type = "solid", seed = 123, from, to, title)

Arguments

y,x

a continuous variable

data

where to find argument y

value

value to identify outliers i.e. for upper tail an outliers is if it is greater than Q_3+value*IQ

with.density

whether a density is required, default is TRUE

hist.col

the colour of lines of the histogram

hist.fill

the colour of the histogram

dens.fill

the color of the density plot

binwidth

the binwidth for the histogram

from

where to start the histogram (you may have to change binwidth)

to

where to finish the histogram (you may have to change binwidth)

point.size

the size of the points in y_dots

point.col

the colour of the points in y_dots

quantile

the quantile values to plot in y_dots, the default is 0.10, .50 and .90

line.col

the color of the vertical lines indicating the 0.10, .50 and .90 quantiles in y_dots

line.type

the type of the verical lines indicationg the 0.10, .50 and .90 quantiles in y_dots

line.size

the size of the verical lines indication the 0.10, .50 and .90 quantiles in y_dots

x.axis.col

the colour of the x-axis

x.axis.line.type

the type of the x-axix

seed

the seed to jitter the y

title

use this for a different title

Value

A ggplot is returned

Author(s)

Mikis Stasinopoulos, Bob Rigby and Fernanda De Bastiani

References

Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC. An older version can be found in https://www.gamlss.com/.

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, https://www.jstatsoft.org/v23/i07/.

Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC.

(see also https://www.gamlss.com/).

van Buuren and Fredriks M. (2001) Worm plot: simple diagnostic device for modelling growth reference curves. Statistics in Medicine, 20, 1259–1277

See Also

plot.ecdf

Examples

library(ggplot2)
y <- rBCT(1000, mu=3, sigma=.1, nu=-1, tau=5)
y_hist(y)
gg <- y_hist(y, with.dens=FALSE)
gg + stat_function(fun = dBCT, args=list(mu=3, sigma=.1,  nu=-1, tau=5), 
                 colour = "black")
gg + stat_function(fun = dBCT, args=list(mu=3, sigma=.1,  nu=-1, tau=5), 
                  geom = "area", alpha=0.5, fill="pink", color="black", n=301)
                  
y_acf(diff(EuStockMarkets[,1]))    

y_dots(rent$R)


gamlss.ggplots documentation built on Sept. 3, 2023, 5:08 p.m.