Skip to content

Commit

Permalink
Update the 'plotdist' function which now supports a vector for the 'b…
Browse files Browse the repository at this point in the history
…reaks' argument
  • Loading branch information
aursiber committed Feb 14, 2024
1 parent 0cf17ff commit 9fbdd72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions R/plotdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ plotdist <- function(data, distr, para, histo = TRUE, breaks="default", demp = F
{
if(demp)
{
if (breaks=="default")
if (identical(breaks, "default"))
h <- hist(data, freq=FALSE, xlab="Data", main="Empirical density", ...)
else
h <- hist(data, freq=FALSE, xlab="Data", main="Empirical density",
Expand All @@ -60,7 +60,7 @@ plotdist <- function(data, distr, para, histo = TRUE, breaks="default", demp = F
}
else
{
if (breaks=="default")
if (identical(breaks, "default"))
h <- hist(data, freq=FALSE, xlab="Data", main="Histogram", ...)
else
h <- hist(data, freq=FALSE, xlab="Data", main="Histogram",
Expand All @@ -81,7 +81,7 @@ plotdist <- function(data, distr, para, histo = TRUE, breaks="default", demp = F
else
{
# plot for discrete data alone
if (breaks!="default")
if (!identical(breaks, "default"))
warning("Breaks are not taken into account for discrete data")
# plot of empirical distribution
t <- table(data)
Expand Down Expand Up @@ -140,7 +140,7 @@ plotdist <- function(data, distr, para, histo = TRUE, breaks="default", demp = F

# plot of empirical and theoretical density
# computes densities in order to define limits for y-axis
if (breaks=="default")
if (identical(breaks, "default"))
h <- hist(data, plot=FALSE)
else
h <- hist(data, breaks=breaks, plot=FALSE, ...)
Expand Down Expand Up @@ -207,7 +207,7 @@ plotdist <- function(data, distr, para, histo = TRUE, breaks="default", demp = F
{
# plot of discrete data with theoretical distribution
par(mfrow=c(1, 2))
if (breaks!="default")
if (!identical(breaks, "default"))
warning("Breaks are not taken into account for discrete distributions")
# plot of empirical and theoretical distributions
t <- table(data)
Expand Down
4 changes: 3 additions & 1 deletion tests/t-plotdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ plotdist(x1)
plotdist(x1, col="blue", type="b", pch=16)
plotdist(x1, type="s")
plotdist(x1, demp = TRUE)
plotdist(x1,demp = TRUE, adjust = 1.5)
plotdist(x1, demp = TRUE, adjust = 1.5)
plotdist(x1, breaks = 2)
plotdist(x1, breaks = seq(-3, 2))

# (2) Plot of a discrete distribution against data
#
Expand Down

0 comments on commit 9fbdd72

Please sign in to comment.