
Last chance! 50% off unlimited learning
Sale ends in
For comparing histograms of two data distributions. Simply input the two distributions, and it generates a clear and informative histogram that illustrates the differences between the data.
compHist(
x1,
x2,
title,
col1 = "red",
col2 = "yellow",
xlab = "",
ylab = "Frequency",
separate = FALSE
)
return histogram comparison using basic histogram plot
NUMERIC. the first distribution
NUMERIC. the second distribution
CHARACTER. title of the histogram plot
CHARACTER. color fill for first distribution
CHARACTER. color fill for second distribution
CHARACTER. label of the x-axis
CHARACTER. label of the y-axis
LOGICAL. whether to separate the plots
col1 = 'dodgerblue4' (and) col2 = 'darksalmon'
col1 = 'brown' (and) col2 = 'beige'
col1 = 'pink' (and) col2 = 'royalblue4'
col1 = 'red' (and) col2 = 'yellow'
col1 = 'limegreen' (and) col2 = 'blue'
col1 = 'darkred' (and) col2 = 'aquamarine4'
col1 = 'purple' (and) col2 = 'yellow'
Users have the option to view individual histograms for each distribution before initiating the comparison, allowing for a detailed examination of each dataset's characteristics. This feature ensures a comprehensive understanding of the data and enhances the user's ability to interpret the results of the distribution comparison provided by this function.
# compare two normal distributions with means that differ a lot
# in this case, the overlap will not be observed
set.seed(123)
compHist(
x1 = rnorm(1000, mean = 3),
x2 = rnorm(1000, mean = 10),
title = "Histogram of Distributions With Means 3 & 10",
col1 = "yellow", col2 = "violet"
)
# compare two normal distributions with means that are close
# in this case, the overlap between the histograms will be observed
set.seed(123)
compHist(
x1 = rnorm(1000, mean = 0),
x2 = rnorm(1000, mean = 2),
title = "Histogram of rnorm Distributions With Means 0 & 2",
col1 = "lightslateblue", col2 = "salmon"
)
set.seed(123)
# separate the plots for preview
compHist(
x1 = rnorm(1000, mean = 0),
x2 = rnorm(1000, mean = 2),
title = c("Plot Means 0", "Plot Means 2"),
col1 = "#F96167", col2 = "#CCF381",
separate = TRUE
)
Run the code above in your browser using DataLab