Learn R Programming

datana (version 1.0.6)

xyhist: A scatterplot with marginal histograms

Description

The function produces a scatterplot between the 'y'-axis variable and the 'x'-axis variable, but also adding the marginal histograms for both variables.

Usage

xyhist(
  x = x,
  y = y,
  col.x = "blue",
  col.y = "red",
  xlab = NULL,
  ylab = NULL,
  x.lim = NULL,
  y.lim = NULL
)

Value

The function returns the above described graph.

Arguments

x

A numeric vector representing the X-axis variable

y

A numeric vector representing the Y-axis variable

col.x

(optional) A string specifying the color of the histogram of the X-variable. Default is "blue".

col.y

(optional) A string specifying the color of the histogram of the Y-variable. Default is "red".

xlab

(optional) A string specifying X-axis label. Default is "xvar".

ylab

(optional) A string specifying Y-axis label. Default is "yvar".

x.lim

(optional) A vector of two elements with the limits of the Y-axis. Default is the range of the X-variable.

y.lim

(optional) A vector of two elements with the limits of the Y-axis. Default is the range of the Y-variable.

Author

Christian Salas-Eljatib

Details

Both the response variable (Y-axis) and the predictor variable (X-axis) must be numeric.

References

- Salas-Eljatib C. 2021. Análisis de datos con el programa estadístico R: una introducción aplicada. Ediciones Universidad Mayor. Santiago, Chile. https://eljatib.com

Examples

Run this code
data(treevolroble)
df <- treevolroble
head(df)
xyhist(x=df$dbh,y=df$toth) 
xyhist(x=df$dbh,y=df$toth, xlab="Variable X",  ylab="Variable Y") 
xyhist(x=df$dbh,y=df$toth, xlab="Variable X", ylab="Variable Y", 
  col.x = "gray",col.y="white")

Run the code above in your browser using DataLab