plot.mixfitEM {mixR}R Documentation

Plotting the Fitted Mixture Models

Description

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.

Usage

## S3 method for class '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"),
  ...
)

Arguments

x

an object of class mixfitEM, an output from the function mixfit

theme

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'.

add_hist

a logical value specifying whether a histogram of data should be plotted

add_poly

a logical value specifying whether a polygon of each component should be plotted.

add_legend

a logical value specifying whether the legend should be plotted.

smoothness

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.

trans

the transparency of the polygons if they are plotted (default 0.5)

cut

the number of standard deviations from the center of each component we want to plot the density (default 3.8)

xlab

the label for x axis

ylab

the label for y axis

title

the title of the plot

breaks

the number of bins used for plotting the histogram

plot.title

an object returned by element_text() to specify the appearance of the title

axis.text.x

an object returned by element_text() to specify the appearance of the x axis

axis.text.y

an object returned by element_text() to specify the appearance of the y axis

axis.title.x

an object returned by element_text() to specify the appearance of the label along x axis

axis.title.y

an object returned by element_text() to specify the appearance of the label along y axis

legend.title

an object returned by element_text() to specify the appearance of the legend title

legend.text

an object returned by element_text() to specify the appearance of the legend text

legend.position

the position of the legend, could be 'right'(default), 'right', 'top', or 'bottom'

legend.direction

the direction of the legend, could be 'vertical' (default) or 'horizontal'

...

other arguments

Details

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.

See Also

mixfit

Examples

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') 


[Package mixR version 0.2.0 Index]