This is the plot method for the class mixfitEM
. It is used to plot the fitted mixture models
by using base R plotting system or using the package ggplot2.
# S3 method for mixfitEM
plot(
x,
theme = NULL,
add_hist = TRUE,
add_poly = TRUE,
add_legend = TRUE,
smoothness = 512,
trans = 0.5,
cut = 3.8,
xlab,
ylab,
title,
breaks,
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(),
axis.text.y = element_text(),
axis.title.x = element_text(),
axis.title.y = element_text(),
legend.title = element_text(),
legend.text = element_text(),
legend.position = "right",
legend.direction = ifelse(legend.position %in% c("top", "bottom"), "horizontal",
"vertical"),
...
)
an object of class mixfitEM
, an output from the function mixfit
a string the specifies the appearance of the plot, which is from the ggplot2 and could be one of'gray', 'bw' (default), 'linedraw', 'light', 'dark', 'minimal', 'classic', or 'void'.
a logical value specifying whether a histogram of data should be plotted
a logical value specifying whether a polygon of each component should be plotted.
a logical value specifying whether the legend should be plotted.
a positive integer controlling the smoothness of the density curve in the plot. The default value is 512 and increasing this value will produce smoother curve.
the transparency of the polygons if they are plotted (default 0.5)
the number of standard deviations from the center of each component we want to plot the density (default 3.8)
the label for x axis
the label for y axis
the title of the plot
the number of bins used for plotting the histogram
an object returned by element_text() to specify the appearance of the title
an object returned by element_text() to specify the appearance of the x axis
an object returned by element_text() to specify the appearance of the y axis
an object returned by element_text() to specify the appearance of the label along x axis
an object returned by element_text() to specify the appearance of the label along y axis
an object returned by element_text() to specify the appearance of the legend title
an object returned by element_text() to specify the appearance of the legend text
the position of the legend, could be 'right'(default), 'right', 'top', or 'bottom'
the direction of the legend, could be 'vertical' (default) or 'horizontal'
other arguments
The function plot.mixfitEM
is used for plotting an object of class mixfitEM
, which is
an output of the function mixfit
. Users can choose base R plotting system or ggplot2
(the package ggplot2 needs to be installed).
plotting system. The plot is a density plot of the fitted mixture model imposed on top of a histogram.
The parameters that control the appearance of the histogram and the density curve can be changed.
The density curve of each component can be shown or hidden.
mixfit
x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 0.7))
mod <- mixfit(x, ncomp = 2)
plot(mod)
plot(mod, theme = 'classic')
Run the code above in your browser using DataLab