plotca {cabootcrs} | R Documentation |
Plotting results with confidence regions
Description
plotca
produces one or more scatterplots of the results of simple or multiple
correspondence analysis, with elliptical confidence regions around chosen points.
Usage
plotca(
x,
datasetname = NULL,
mytitles = NULL,
showrowlabels = TRUE,
showcolumnlabels = TRUE,
plotsymbolscolours = c(19, "inferno", 18, "inferno"),
othersmonochrome = "grey",
crpercent = 95,
usebootcrits = NULL,
plottype = "biplot",
showrowcrs = TRUE,
showcolumncrs = TRUE,
likertarrows = FALSE,
firstaxis = 1,
lastaxis = 2,
plotallpairs = "successive",
picsize = NULL,
mcaoneploteach = TRUE,
mcashowindividuals = FALSE,
mcavariablecolours = FALSE,
mcacategorycolours = FALSE,
groupings = NULL,
grouplabels = NULL,
eps = 1e-15,
plotwithdevnew = FALSE
)
Arguments
x |
An object of class |
datasetname |
A string to use as the name of the data set in the plots, defaults to that in cabootcrs object |
mytitles |
A list of text strings, to be used instead of the default titles of the plots, where the list must be at least as long as the number of plots to be produced |
showrowlabels |
If TRUE then label row points as usual, otherwise suppress labels of row points. Note: when analysing a Burt matrix the columns points are plotted |
showcolumnlabels |
If TRUE then label column points as usual, otherwise suppress labels of column points. Note: when analysing a Burt matrix the columns points are plotted |
plotsymbolscolours |
A vector/list of length 1, 2, 4 or equal to the number of category points to be plotted. (a) If longer than length 4 then it contains the colours for all the points, their ellipses and labels. Taken to be a vector or list of valid R colours, length at least equal to the number of category points to be plotted, in the order rows followed by columns for sca or variable categories in order for mca. The colours can be named (e.g. "azure2") or RGB hexadecimal (e.g. "#1173B3"), and can be subsetted from colours() or from the colo(u)rspace library's palettes. (b) If length 4 then it takes the form: c(row symbol, "row colour", column symbol, "column colour") giving plot symbols and colours for row and column points and ellipses when they are the primary points.
(c1) If length 2 and the first element is a valid colour choice as above then it takes the form: c("row colour", "column colour") giving colours for row and column points and ellipses when they are the primary points.
(c2) If length 2 and the first element is *not* a valid colour choice as above then it takes the form: c(column symbol, "column colour") giving plot symbols and colours for column points and ellipses when they are the primary points.
(d) If length 1 then it takes the form: "column colour" giving colours for column points and ellipses when they are the primary points, choices as second element above. Note: colour can also be specified as colours()[i] which picks out the i-th colour. Note: when analysing a Burt matrix the columns points are plotted. The idea behind "alldifferent" etc is that the colours change gradually, so that if the order of the rows/columns is meaningful then the colour change tracks this. Note: groupings and grouplabels below override all this. |
othersmonochrome |
Either:
|
crpercent |
The nominal coverage percentage of the confidence ellipses (90, 95 or 99 only if using bootstrap critical values) |
usebootcrits |
Whether to use bootstrap critical values for the ellipses:
Note: only 90%, 95% and 99% bootstrap critical values are available |
plottype |
This is only relevant for simple CA, in MCA the choice is automatic.
|
showrowcrs |
Whether to plot confidence ellipses for row points:
Note: when analysing a Burt matrix the columns points are plotted |
showcolumncrs |
Whether to plot confidence ellipses for column points:
Note: when analysing a Burt or indicator matrix the column points are plotted, the columns being all of the variable categories, ordered by variable number, e.g. for p=3 variables each with 5 categories then columns 6:10 are variable 2. Note: in MCA this is overridden by mcaoneploteach=TRUE, in which case there is one plot per variable, automatically giving ellipses for each of its categories. |
likertarrows |
If TRUE then, for MCA on likert-type ordered categorical data,
draw arrows connecting the category points for each variable,
with the arrows drawn from a category point to the next higher category point. |
firstaxis |
Number of the first (i.e. highest inertia) axis to be plotted |
lastaxis |
Number of the last (i.e. lowest inertia) axis to be plotted, which must be <= axisvariances value for x. |
plotallpairs |
Whether to plot all pairs of axes against each other:
|
picsize |
A 2-vector/list or 4-vector/list specifying the plot size:
All plots have an aspect ratio of 1. The same scales are used for all plots, so in the biplot case it might occasionally be preferred to run plotca twice with different picsize values, one being better for rows in principal coordinates and the other better for columns in principal coordinates. If picsize is used to focus in on a particular area of the plot then biplot labels might not appear properly. If using Rstudio then it may override this somewhat, especially if you resize the plot window after plotting. If Rstudio has too much of a mind of its own when plotting then try plotwithdevnew=TRUE to put each plot in a new window, as in standard R. |
mcaoneploteach |
For MCA only, a flag or list of column numbers saying whether to produce one plot for each variable, where confidence ellipses are shown for that variable but not others:
|
mcashowindividuals |
For MCA on an indicator matrix only, a flag saying whether to plot the individuals on the plot(s):
|
mcavariablecolours |
If TRUE then the only valid colour options for plotsymbolscolours are "viridis", "inferno", "alldifferent", "differentreds" or "differentblues" as above. Note: if plotsymbolscolours has length > 4, and so is specifying a colour for each category, then it overrides this. |
mcacategorycolours |
If TRUE then the only valid colour options for plotsymbolscolours are "viridis", "inferno", "alldifferent", "differentreds" or "differentblues" as above. Note: if plotsymbolscolours has length > 4, and so is specifying a colour for each category, then it overrides this. |
groupings |
The name of a file (in " ") or data frame containing group structure of row and column points: the n rows are divided into m groups and the p columns divided into k groups the file or data frame is n+p by 2, where: first column is 1..n 1..p (to make the file easier to read) Hence the file or data frame is: 1 <the number of the group-of-rows to which row 1 belongs> |
grouplabels |
The name of the file (in " ") or data frame containing the colours and labels to be used, in association with the groupings option above, in a m+k by 5 array: 1 <legend> <plot symbol> <plot colour> <draw ellipse?> The first column contains the number of the group-of-rows or group-of-columns, the others are:
See Details section and examples below to make more sense of this. This can also be used for multiple CA, remembering that only column points are shown (usually) and that columns are ordered by variable and then by category, so that three variables each with 5 categories will be columns 1:5, 6:10 and 11:15 respectively. It should not be used when mcaoneploteach=TRUE, however, as that already takes care of this sort of grouping. These options are particularly intended for large data sets, to allow attention to be drawn to some points above others, to emphasize any group structure within the data, or to show only the most important ellipses in order to make the picture less cluttered. |
eps |
Any value less than this is treated as zero in some calculations and comparisons |
plotwithdevnew |
When using Rstudio, a flag saying whether to put each plot in a new device (plot window) or just use the default Rstudio plot pane:
|
Details
In the following, the categories for which confidence regions are being shown are referred to as the primary points, the others as the secondary points. The primary points are always plotted in principal coordinates while the secondary points can be in standard (biplot style in simple CA) or principal (french style in simple CA, always in multiple CA) coordinates.
The default colour scheme is for the primary points and their confidence ellipses to be plotted each in a different colour, as this makes it easier to see which ellipse goes with which point, while the secondary points are all plotted in monochrome to make it easier to distinguish between the two sets of points. This can all be controlled by the user. Note that a point will still be treated as a primary point and plotted with its own colour even when the plotting of its ellipse is suppressed with the showrowcrs or showcolumncrs options.
Note that the plots will look better if saved as .eps or .pdf rather than as .jpg or .png.
(1) Simple CA
Two plots are produced, in each plot one set of points (rows or columns) is regarded as
the primary set and is plotted in principal coordinates with confidence regions shown:
- one plot shows confidence regions for rows in principal coordinates
- one plot shows confidence regions for columns in principal coordinates
The other set of points (columns or rows) is regarded as the secondary set and the plotting
depends on the choice of biplot or french-style plot:
biplot - secondary points shown as directions in standard coordinates
french - secondary points shown in principal coordinates
(2) Multiple CA
All points are plotted in principal coordinates ("french")
Burt matrix (mcatype="Burt"):
a) only plot the columns of the Burt matrix (the rows are the same)
b) plot all variable categories, i.e. columns
c) if mcaoneploteach=TRUE then produce p plots, each with CRs for all categories of one of the variables,
otherwise produce one plot showing CRs for all variables (busy)
d) Columns are ordered by variable then category
(e.g. for p=3 with 5 categories each, columns 6:10 are variable 2)
Indicator matrix (mcatype="indicator"):
a) if mcashowindividuals=TRUE then plot individual (row) points, without CRs
b) as Burt for variables
Indicator matrix (mcatype="indicator") with experimental likert resampling (cabootcrs had mcaindividualboot=TRUE):
a) if mcashowindividuals=TRUE then plot individual (row) points, with CRs (busy)
b) as Burt for variables
(3) Critical values
Critical values for the ellipses default to those specified in cabootcrs, which default to bootstrap critical values
(4) Choosing colours and which ellipses to show
The showrowcrs, showcolumncrs, showrowlabels, showcolumnlabels and othersmonochrome options are available as ways of reducing plot clutter in large data sets, for example by showing the column points unlabelled and monochrome as a way of drawing the eye to the multicoloured row points and ellipses.
The default is for each primary point to be in a different colour, with secondary points in the colour defined by othersmonochrome (default grey). If othersmonochrome=NULL then secondary points are also plotted with different colours.
The plotsymbolscolours option can be used to specify quickly the set of symbols and colours used, with the options described in (5) below giving far more control at the cost of extra work.
The default colour scheme is grDevices:inferno, but with k+2 colours picked and then 2:k+1 used, because the end colour is a bit too yellow and hard to see.
Note that french-style plots in simple CA are often less cluttered because they omit the biplot lines, while they also show the two sets of points on similar scales so that it is easier to fit all the points on one picture without cropping or excessive empty space.
(5) Specifying colours for (groups of) points and ellipses
For large matrices the plots from exploratory multivariate methods are often so busy that the whole point of the method, to clarify the structure of the data, is nullified. This is even more of a problem when confidence regions are shown on the plots.
Hence points can be defined in groups as below, so you can divide them into groups in one or more ways, e.g. rows 1-3 in red and rows 4-8 in blue, or rows 1-5 in green and rows 6-8 in orange etc.
The groupings and grouplabels options are chosen via separate text files or data frames to define the groups of points. If groupings is left null then plotsymbolscolours is used instead.
There are two ways of defining groupings and group labels. The first of these is by defining a pair of data frames within R and supplying them as parameters either to cabootcrs initially or to plotca. This method works in R CMD check and hence is the one used in the examples, but as you can see is rather hard to follow.
To plot with colours defined using groups-of-points:
bd <- cabootcrs(DreamData)
Then define the groups using data frames in R or text files:
(5a) Using data frames
These data frames define the same groupings and colours as the files below, see the files for a clearer explanation:
bd <- cabootcrs(DreamData) groupingsframe <- cbind(c(1:5,1:4),c(1,1,2,2,3,1,1,2,2)) grouplabframe <- cbind( c(1,2,3,1,2), c("AB","CD","E","ab","cd"), c(19,20,21,"+","*"), c("green","blue","yellow","red","orange"), "T" ) plotca(bd, groupings=groupingsframe, grouplabels=grouplabframe)
(5b) Using text files
A version which produces identical results, but does not work in R CMD check, is usually much easier for the user as they can be edited outside R. The groupings and group labels are defined in files, present in the directory specified in setwd(). To obtain identical results to the above, create two text files as below:
DreamGroupings.txt contains
1 1 2 1 3 2 4 2 5 3 1 1 2 1 3 2 4 2
e.g. the first two lines show that rows 1,2 belong to group-of-rows 1, while the last two lines show that columns 3,4 belong to group-of-columns 2.
DreamGroupLabels.txt contains
1 AB 19 "green" T 2 CD 20 "blue" T 3 E 21 "yellow" T 1 ab + "red" T 2 cd * "orange" T
e.g. group-of-rows 1 will be shown in green and plotted with symbol 19, with the legend AB.
bd <- cabootcrs(DreamData, showresults=FALSE) plotca(bd, groupings="DreamGroupings.txt", grouplabels="DreamGroupLabels.txt")
(5c) General use
Even without groupings this can be used to specify all colours, simply by specifying each point as its own group, in this case rows 1-5 and columns 1-4 define row groups 1-5 and column groups 1-4, no legend is required so repeat "", choose 9 plot symbols and 9 colours.
Hence to plot each point with its own specified colour and symbol:
bd <- cabootcrs(DreamData, showresults=FALSE) groupingsframe <- cbind(c(1:5,1:4),c(1:5,1:4)) grouplabframe <- cbind( c(1:5,1:4), rep("",9), 11:19, c("green","blue","yellow","red","orange","grey1","grey22","grey44","grey66"), "T" ) plotca(bd, groupings=groupingsframe, grouplabels=grouplabframe)
Note: plotsymbolscolours can be used to plot with a different colour for each category point, but with default symbols.
(5d) MCA use
As before, but need to specify for both row and column categories even though only column categories will be plotted,
so just duplicate the data frames (yes I know it's a bodge).
Hence to plot each point with your own choice of colour and symbol:
bd3 <- cabootcrs(DreamData223by3, catype="mca", varandcat=FALSE) groupingsframe <- cbind(1:12,1:12) groupingsframe <- rbind(groupingsframe,groupingsframe) grouplabframe <- cbind( 1:12, rep("",12), 11:22, c("green","blue","yellow","red","orange","grey1","grey22","grey44","grey66","coral1","coral2","coral3"), "T" ) grouplabframe <- rbind(grouplabframe,grouplabframe) plotca(bd3, groupings=groupingsframe, grouplabels=grouplabframe)
This can also be used to specify colours and symbols for each variable in MCA, but note that you are still specifying for each column point, so that you need to know how many categories each variable has - a simpler way to do this will be added to a later update.
ost <- cabootcrs(OsteoDataNames, catype="mca", varandcat=FALSE) totcolumns <- ost@columns totvars <- ost@p numcats <- ost@Jk cats <- NULL for (i in 1:totvars) { cats <- c(cats,rep(i,numcats[i])) } groupingsframe <- cbind(1:totcolumns,cats) groupingsframe <- rbind(groupingsframe,groupingsframe) grouplabframe <- cbind( 1:totvars, rep("",totvars), rep(19,totvars), c("blue","red","green","darkgreen","green3","black","grey1","coral1","coral2","coral3","navy"), "T" ) grouplabframe <- rbind(grouplabframe,grouplabframe) plotca(ost, groupings=groupingsframe, grouplabels=grouplabframe)
This can also be used to plot the individual points with colours to denote groups, for example in the below the first 100 individual points are plotted with one colour, the rest with another, while all columns get their own colour.
bd3indnoboot <- cabootcrs(DreamData223by3,catype="mca",mcatype="indicator",varandcat=FALSE,nboots=0) rowgroups <- cbind( 1:223, c(rep(1,100),rep(2,123)) ) colgroups <- cbind(1:12,1:12) groupingsframe <- rbind( rowgroups, colgroups ) rowlabs <- cbind( 1:2, c("1-100","101-223"), c("+","+"), c("black","grey"), "T") collabs <- cbind( 1:12, rep("",12), "*", c("green","cyan","yellow","red","orange","blue","blue1","blue2","blue3","coral1","coral2","coral3"), "T" ) grouplabframe <- rbind(rowlabs,collabs) plotca(bd3indnoboot, groupings=groupingsframe, grouplabels=grouplabframe, mcashowindividuals=TRUE, mcaoneploteach=FALSE, showrowlabels=FALSE, othersmonochrome=NULL, picsize=c(-.36,.36))
(6) Plotting results from cabootcrs() using ellipse() or ca()
This can be used with the ellipse() package to add the confidence ellipse to a picture from another package
Example: confidence ellipse for row or column i on axes 1,2 from cabootcrs output Results is:
lines(ellipse(x=covmat(Results,i,"row",1,2,FALSE), centre=Results@Rowprinccoord[i,cbind(1,2)], npoints=1000), cex=1, pch=".", col="blue") lines(ellipse(x=covmat(Results,i,"column",1,2,FALSE), centre=Results@Colprinccoord[i,cbind(1,2)], npoints=1000), cex=1, pch=".", col="blue")
Example: to add row CRs to a plot from the ca() package to data set TheData
Results <- cabootcrs(TheData, showresults=FALSE) caResults <- ca(TheData) plot(caResults) for (i in 1:dim(TheData)[1]) { lines(ellipse(x=covmat(Results,i,"row",1,2,FALSE), centre=Results@Rowprinccoord[i,cbind(1,2)], npoints=1000), cex=1, pch=".", col="blue") }
However note that reflectaxes() may also be needed.
(7) Note
Note that plotca, summaryca and printca are all defined as new functions, rather than as overloaded versions of plot, summary and print, simply in order to avoid complication and unintended consequences within R
Value
One or more plots are produced but no output object is created
See Also
cabootcrs-package
, cabootcrs
,
printca
, summaryca
, cabootcrsresults
Examples
# the main function also calls plotca with the default options
bd <- cabootcrs(DreamDataNames, datasetname="Maxwell's dream data",
varnames=c("Age groups","Severity of disturbance"),showresults=FALSE)
plotca(bd)
## Not run:
### Plot options for SCA:
# Note that Rstudio changes plots depending on the size of your plot window,
# so the picsize parameter (used for xlim, ylim in the plot command) is partially
# overridden, so warnings that a point is outside the plot limits may not be correct
# Plot with specified size to fit the whole of the arrows in without cropping
plotca(bd, picsize=c(-2.5,2.5))
# or smaller, note the warning
plotca(bd, picsize=c(-0.5,0.5))
# Replacing the plot titles with your own
plotca(bd, mytitles=c("Plot 1 Title line 1\nline 2\nline 3","Plot 2 Title line 1\nline 2\nline 3" ))
# All points in colour
plotca(bd,othersmonochrome=NULL)
# 90% regions in reds and blue
plotca(bd, plotsymbolscolours=c(3,"differentreds","*","blue"), crpercent=90)
# Many different colour schemes and ways of specifying colours and symbols
# Specify colour/colour scheme and symbols
plotca(bd, plotsymbolscolours=c(3,"differentreds","*","blue") )
plotca(bd, plotsymbolscolours=c(3,"viridis") )
plotca(bd, plotsymbolscolours="inferno" )
plotca(bd, plotsymbolscolours=colours()[641] )
# Just give a list of colours, one for each category point
plotca(bd,
plotsymbolscolours=c("green","blue","yellow","red","orange","red","blue","tan1","orchid4") )
plotca(bd, plotsymbolscolours=colours()[161:170] )
plotca(bd, plotsymbolscolours=colours()[c(111:115,561:564)] )
# This time using colo(u)rspace package colour palettes
library(colorspace)
plotca(bd, plotsymbolscolours=hcl.colors(9,palette="Peach") )
plotca(bd, plotsymbolscolours=hcl.colors(50,palette="Mint")[c(11:15,31:34)] )
plotca(bd,
plotsymbolscolours=c(sequential_hcl(bd@rows,"Blues 3"),sequential_hcl(bd@columns,"Reds 3")) )
# suppress labels for column points, to de-clutter row points picture,
# this is mostly useful for larger data sets than this one
plotca(bd, showcolumnlabels=FALSE)
# only show ellipses for rows 1, 1-2 and 1-3 respectively
plotca(bd, showrowcrs=1)
plotca(bd, showrowcrs=c(1,2))
plotca(bd, showrowcrs=1:3)
# plot axes 1 v 2, 1 v 3 and 2 v 3
plotca(bd, firstaxis=1, lastaxis=3, plotallpairs="all")
# If the cell values were all 10 times larger
bdx10 <- cabootcrs(10*DreamData)
plotca(bdx10,plottype = "french",picsize=c(-0.4,0.4))
# Various plots for a larger data set, note that the default colour scheme picks out
# males, females and ages because of the ordering of the rows
bs <- cabootcrs(SuicideData)
plotca(bs, picsize=c(-0.7,0.8))
plotca(bs, plottype="french", picsize=c(-0.7,0.8))
plotca(bs, plottype="french", picsize=c(-0.7,0.8),
plotsymbolscolours=c(".","inferno","+","black"))
# Note that the ellipses follow the horseshoe
bas <- cabootcrs(AsbestosData)
# more complicated plotting, define group structure in data frames
groupingsframe <- cbind( c(1:5,1:4), c(1,1,2,2,3,1,1,2,2) )
grouplabframe <- cbind( c(1,2,3,1,2), c("AB","CD","E","ab","cd"), c(19,20,21,"+","*"),
c("green","blue","yellow","red","orange"), "T" )
plotca(bd, groupings=groupingsframe, grouplabels=grouplabframe)
plotca(bd, groupings=groupingsframe, grouplabels=grouplabframe, plottype="french")
# This can also be used for custom colour schemes other than "differentreds" etc as
# defined in the plotsymbolscolours option, though note that R colours are not ordered in the
# way you might expect, so the colour scheme below is purely illustrative and not very sensible
customframe <- cbind( c(1:5,1:4), c(1:5,1:4) )
customlabframe <- cbind( c(1:5,1:4), rep("",9), c(rep(18,5),rep(19,4)),
colours()[c(seq(10,130,30),seq(440,590,50))], "T" )
plotca(bd, groupings=customframe, grouplabels=customlabframe)
### Plot options for MCA:
# Use one of the below, labelling row A as R:A or just A (etc) as preferred
bd3 <- cabootcrs(DreamData223by3, catype="mca",
datasetname="Dream data with extra random column")
bd3 <- cabootcrs(DreamData223by3, catype="mca", varandcat=FALSE,
datasetname="Dream data with extra random column")
# just variable 2
plotca(bd3,mcaoneploteach=2)
# just variables 1 and 3
plotca(bd3,mcaoneploteach=c(1,3))
# one plot showing CRs for all variable categories (busy)
plotca(bd3,mcaoneploteach=FALSE)
# each variable has its own colour
plotca(bd3,mcavariablecolours=TRUE)
# each category number has its own colour
plotca(bd3,mcacategorycolours=TRUE)
# draw arrows between successive ordered categories
plotca(bd3,likertarrows=TRUE)
# secondary points black rather than grey
plotca(bd3,othersmonochrome="black")
# 99% CRs
plotca(bd3,crpercent=99)
# Plot together CRs for the first category of each variable
plotca(bd3,showcolumncrs=c(1,6,10),mcaoneploteach=FALSE)
# Plot together CRs for the second category of each variable
plotca(bd3,showcolumncrs=c(2,7,11),mcaoneploteach=FALSE)
# One plot with CRs only for variable 3
plotca(bd3,showcolumncrs=10:12,mcaoneploteach=FALSE)
# Three plots, various colour schemes
plotca(bd3,othersmonochrome="black")
plotca(bd3,othersmonochrome="black",mcacategorycolours=TRUE)
plotca(bd3,mcavariablecolours=TRUE,likertarrows=TRUE)
# All on one plot, various colour schemes, very busy
plotca(bd3,mcaoneploteach=FALSE,showcolumncrs=1:5,othersmonochrome="black")
plotca(bd3,mcaoneploteach=FALSE,showcolumncrs=1:5,likertarrows=TRUE)
plotca(bd3,mcaoneploteach=FALSE,likertarrows=TRUE,mcacategorycolours=TRUE)
plotca(bd3,mcaoneploteach=FALSE,likertarrows=TRUE,mcavariablecolours=TRUE)
# Plots with more complicated colour and grouping structure, as above but now in MCA case.
# Note the need to duplicate both data frames as groupings must be specified for both rows
# and columns, though only columns are used.
# Note also that symbol types need to be defined either all as numbers or all as symbols
groupingsframe <- cbind(1:12,c(1,1,2,2,3,4,4,5,5,6,7,7))
groupingsframe <- rbind(groupingsframe,groupingsframe)
grouplabframe <- cbind( 1:7, c("AB","CD","E","ab","cd","v1","v23"), 19:25,
c("cyan","deepskyblue","blue","red","tomato","chartreuse","green"),
"T" )
grouplabframe <- rbind(grouplabframe,grouplabframe)
plotca(bd3, groupings=groupingsframe, grouplabels=grouplabframe,
mcaoneploteach=FALSE)
### Adding confidence ellipses to plots from ca package ca() and mjca() functions
## Simple CA
# Adding confidence ellipses for row points to plots from ca() using ellipse()
# Note: reflectaxes() is needed if cabootcrs() and ca() axes are reflected wrt each other
library(ca)
library(ellipse)
cad <- ca(DreamData)
plot(cad)
for (i in 1:dim(DreamData)[1]) {
lines( ellipse(x=covmat(bd,i,"row",1,2,FALSE), centre=bd@Rowprinccoord[i,cbind(1,2)],
npoints=1000),
cex=1, pch=".", col="blue")
}
# These plots can also be produced almost identically here
bd <- cabootcrs(DreamData, showresults=FALSE)
# both plots almost the same as the default plot from ca()
plotca(bd, plottype="french", showrowcrs=FALSE, showcolumncrs=FALSE, othersmonochrome=NULL,
plotsymbolscolours=c(19,"blue",17,"red"), picsize=c(-0.5,0.6) )
# plot almost the same as the ca() plot, but with ellipses added
plotca(bd, plottype="french", othersmonochrome=NULL, plotsymbolscolours=c(19,"blue",17,"red"),
picsize=c(-0.5,0.6))
## Multiple CA
# Adding confidence ellipses for category points to plots from mjca() using ellipse()
# Note that ca also uses standardised inertias and coordinates by default
library(ca)
library(ellipse)
cad3 <- mjca(DreamData223by3)
# Obtain covariance matrices, using same scalings and standardisations
bd3 <- cabootcrs(DreamData223by3, catype="mca", showresults=FALSE)
# Reflect axis 1 for consistency (may differ on other machines)
bd3 <- reflectaxes(bd3,1)
# Plot and then add ellipses for categories of variable 1 only
plot(cad3)
for (i in 1:bd3@Jk[1]) {
lines( ellipse(x=covmat(bd3,i,"column",1,2,FALSE), centre=bd3@Colprinccoord[i,cbind(1,2)],
npoints=1000),
cex=1, pch=".", col="red")
}
# These plots can also be produced almost identically here
plotca(bd3,picsize=c(-0.35,0.35), mcaoneploteach=FALSE, mcavariablecolours=TRUE,
showcolumncrs=FALSE)
plotca(bd3,picsize=c(-0.35,0.35), mcaoneploteach=FALSE, plotsymbolscolours=c(17,"red"),
showcolumncrs=FALSE)
plotca(bd3,picsize=c(-0.35,0.35), mcaoneploteach=FALSE, mcacategorycolours=TRUE,
showcolumncrs=1:5 )
# Three separate plots with ellipses for one variable on each
for (j in 1:length(bd3@Jk)) {
plot(cad3)
if (j==1) { firstcol <- 1 } else { firstcol <- cumsum(bd3@Jk)[j-1]+1 }
for (i in firstcol:cumsum(bd3@Jk)[j]) {
lines( ellipse(x=covmat(bd3,i,"column",1,2,FALSE), centre=bd3@Colprinccoord[i,cbind(1,2)],
npoints=1000),
cex=1, pch=".", col="red")
}
}
# For comparison, default plot with one plot each showing the ellipses for each variable
plotca(bd3,picsize=c(-0.35,0.35), mcacategorycolours=TRUE )
## End(Not run)