Usage
plotpc(x, xrange=NULL, hist=TRUE, main="Principal components", xlab=NULL, ylab=NULL, gp.points=gpar(cex=.6), pch=20, height=xrange/10, breaks="Sturges", adjust=1, gp.hist=if(hist) gp.hist <- gpar(col="gray", fill="gray") else gp.hist <- gpar(col="black"), gp.text=gpar(cex=.8, font=2), gp.axis=gpar(col="gray", lwd=2), sd.ellipse=NA, gp.ellipse=gpar(col="gray", lwd=2), heightx=NULL, breaksx=NULL, adjustx=NULL, gp.histx=NULL, textx="", gp.textx=NULL, axis.lenx=0, gp.axisx=NULL, heighty=NULL, breaksy=NULL, adjusty=NULL, gp.histy=NULL, texty="", gp.texty=NULL, axis.leny=0, gp.axisy=NULL, height1=NULL, flip1=FALSE, breaks1=NULL, adjust1=NULL, gp.hist1=NULL, offset1=NULL, text1=NULL, gp.text1=NULL, axis.len1=2, gp.axis1=NULL, height2=NULL, flip2=FALSE, breaks2=NULL, adjust2=NULL, gp.hist2=NULL, offset2=NULL, text2=NULL, gp.text2=NULL, axis.len2=2, gp.axis2=NULL, angle3=NA, height3=NULL, flip3=FALSE, breaks3=NULL, adjust3=NULL, gp.hist3=NULL, offset3=NULL, text3=NULL, gp.text3=NULL, axis.len3=0, gp.axis3=NULL, angle4=NA, height4=NULL, flip4=FALSE, breaks4=NULL, adjust4=NULL, gp.hist4=NULL, offset4=NULL, text4=NULL, gp.text4=NULL, axis.len4=0, gp.axis4=NULL, angle5=NA, height5=NULL, flip5=FALSE, breaks5=NULL, adjust5=NULL, gp.hist5=NULL, offset5=NULL, text5=NULL, gp.text5=NULL, axis.len5=0, gp.axis5=NULL, angle6=NA, height6=NULL, flip6=FALSE, breaks6=NULL, adjust6=NULL, gp.hist6=NULL, offset6=NULL, text6=NULL, gp.text6=NULL, axis.len6=0, gp.axis6=NULL, angle7=NA, height7=NULL, flip7=FALSE, breaks7=NULL, adjust7=NULL, gp.hist7=NULL, offset7=NULL, text7=NULL, gp.text7=NULL, axis.len7=0, gp.axis7=NULL, yonx = FALSE, offset.yonx=-xrange/2.5, text.yonx="y~x", gp.text.yonx=NULL, axis.len.yonx=xrange/2.5, gp.axis.yonx=gpar(col=1), xony = FALSE, offset.xony=-xrange/2.5, text.xony="x~y", gp.text.xony=NULL, axis.len.xony=xrange/2.5, gp.axis.xony=gpar(col=1))
Arguments
x
A two column matrix or dataframe.
The principal components of the x
will be calculated
treating each column as a variable.
hist
Default TRUE
to plot histograms.
Set to FALSE
to plot densities instead.
The various "histogram" arguments will then
apply to densities rather than to histograms.
xrange
The range of the x axis.
That is, xlim
will be
c(mean(x[,1]) - xrange/2, mean(x[,1]) + xrange/2
),
and ylim
will have the same range about mean(x[,2])
.
Default NULL
, meaning automatically deduce axis limits from
the x
argument.
main
Main title.
Default "Principal components"
.
xlab
x axis label.
Default NULL
, meaning create the label automatically from the column names of x
.
ylab
y axis label.
Default NULL
, meaning create the label automatically from the column names of x
.
gp.points
Graphic parameters for the plotted points.
Default gpar(cex=.6)
.
pch
Plot character for the plotted points.
Default 20
.
The following arguments apply to all histograms.
These can be overridden by using the histogram-specific argument
e.g. override the height
argument for the first principal
component by specifying height1
.
height
Height of histograms.
Default xrange/10
.
Use a negative height to flip a histogram around its base.
breaks
Passed on to hist
.
Default "Sturges"
.
Using something like breaks=12
can be useful.
adjust
Passed on to density
.
Default 1
.
Use something like adjust=.5
for more details in the density plots.
gp.hist
Graphic parameters for the histograms or densities.
If hist==TRUE
then the default is
gpar(col="gray", fill="gray")
where
col
is the color of the lines delineating the histograms,
and fill
is the color filling the histograms.
If hist==FALSE
then the default is
gpar(col="black")
.
gp.axis
Graphic parameters for the axis drawn through the scatter of points.
Default gpar(col="gray", lwd=2)
meaning draw the axes as thickish gray lines.
sd.ellipse
If greater than 0, draw a confidence ellipse
for the principal components at sd.ellipse
standard deviations.
Default is NA
, meaning do not draw an ellipse.
gp.ellipse
Graphic parameters for the ellipse.
Default gpar(col="gray", lwd=2)
.
gp.text
Graphic parameters for text above the histograms.
Default gpar(cex=.8, font=2)
.
The following arguments apply to the histogram on the x axis.
heightx
Default NULL
, meaning use height
.
Use 0
to not plot the x histogram.
breaksx
Default NULL
, meaning use breaks
.
adjustx
Default NULL
, meaning use adjust
.
gp.histx
Default NULL
, meaning use gp.hist
.
textx
Text drawn above the histogram.
Default ""
, meaning no text.
The text is drawn using gp.textx
.
gp.textx
Graphic parameters for the text above the histogram.
Default NULL
, meaning use gp.text
.
axis.lenx
Length of horizontal line drawn through the center of the points.
Units are standard deviations of x[,1]
.
Default 0
, meaning do not plot a horizontal axis.
gp.axisx
Default NULL
, meaning use gp.axis
.
heighty, breaksy, adjusty, gp.histy, texty, gp.texty, axis.leny, gp.axisy
As above but for the histogram on the y axis.
The following arguments apply to the first principal component.
height1
Default NULL
, meaning use height
.
Use 0
to not plot the histogram for the first principal component.
flip1
Flip the position of the histogram around the axis of the first principal component.
Default FALSE
, meaning do not flip.
breaks1
Default NULL
, meaning use breaks
.
adjust1
Default NULL
, meaning use adjust
.
gp.hist1
Default NULL
, meaning use gp.hist
.
offset1
Distance of the histogram plot from the center of the graph, in native units.
Default NULL
, meaning automatic.
text1
Text drawn above the histogram.
Default NULL
, meaning generate the text automatically.
Use ""
for no text.
The text is drawn using gp.text1
.
gp.text1
Graphic parameters for the text above the histogram.
Default NULL
, meaning use gp.text
.
axis.len1
Length of line drawn along the first principal axis.
Units are standard deviations of the points projected onto that axis.
Default 2
, meaning draw a line of length plus and minus two standard deviations.
Use 0
for no axis.
gp.axis1
Default NULL
, meaning use gp.axis
.
height2, flip2, breaks2, adjust2, gp.hist2, offset2, text2, gp.text2, axis.len2, gp.axis2
As above but for the second principal component.
The following arguments apply to the optional histogram at angle3.
By default, angle3=NA
, meaning do not plot the histogram.
Use, say, angle3=45
to plot a histogram at 45 degrees.
By setting angle3
to angle7
you
can plot up to five extra histograms at any angles.
angle3
Default NA
, meaning do not plot a histogram.
Use, say, angle3=45
to plot a histogram at 45 degrees.
height3
Default NULL
, meaning use height
.
breaks3
Default NULL
, meaning use breaks
.
adjust3
Default NULL
, meaning use adjust
.
gp.hist3
Default NULL
, meaning use gp.hist
.
offset3
Default NULL
, meaning automatic.
text3
Default NULL
, meaning automatic.
gp.text3
Default NULL
, meaning use gp.text
.
axis.len3
Length of axis drawn at angle3
through the scatter of points.
Default 0
, meaning do not plot the axis.
gp.axis3
Default NULL
, meaning use gp.axis
.
angle4, height4, flip4, breaks4, adjust4, gp.hist4, offset4, text4, gp.text4, axis.len4, gp.axis4
As above but for the angle4
histogram.
angle5, height5, flip5, breaks5, adjust5, gp.hist5, offset5, text5, gp.text5, axis.len5, gp.axis5
As above but for the angle5
histogram.
angle6, height6, flip6, breaks6, adjust6, gp.hist6, offset6, text6, gp.text6, axis.len6, gp.axis6
As above but for the angle6
histogram.
angle7, height7, flip7, breaks7, adjust7, gp.hist7, offset7, text7, gp.text7, axis.len7, gp.axis7
As above but for the angle7
histogram.
The following arguments apply to the optional "y on x" regression line.
yonx
TRUE to plot a "y on x" linear regression line. Default FALSE.
offset.yonx
Position of text plotted on regression line.
Default -xrange/2.5
.
text.yonx
Text plotted on the regression line. Default "y~x"
.
gp.text.yonx
Graphic parameters for the text plotted on the regression line.
Default NULL
, meaning use gp.text
.
axis.len.yonx
Length of regression line in gpar
"native"
units.
Default -xrange/2.5
.
gp.axis.yonx
Graphic parameters for the regression line.
Default gpar(col=1)
.
xony, offset.xony, text.xony, gp.text.xony, axis.len.xony, gp.axis.xony
As above but for a "x on y" regression.