ggbplot {Correlplot} | R Documentation |
Create a biplot with ggplot2
Description
Function ggbiplot
creates a biplot of a matrix with ggplot2 graphics.
Usage
ggbplot(A, B, main = "", circle = TRUE, xlab = "", ylab = "", main.size = 8,
xlim = c(-1, 1), ylim = c(-1, 1), rowcolor = "red", rowch = 1, colcolor = "blue",
colch = 1, rowarrow = FALSE, colarrow = TRUE)
Arguments
A |
A dataframe with coordinates and names for the biplot row markers |
B |
A dataframe with coordinates and names for the biplot column markers |
main |
A title for the biplot |
circle |
Draw a unit circle ( |
xlab |
The label for the x axis |
ylab |
The label for the y axis |
main.size |
Size of the main title |
xlim |
Limits for the horizontal axis |
ylim |
Limits for the vertical axis |
rowcolor |
Color used for the row markers |
rowch |
Symbol used for the row markers |
colcolor |
Color used for the column markers |
colch |
Symbol used for the column markers |
rowarrow |
Draw arrows from the origin to the row markers ( |
colarrow |
Draw arrows from the origin to the column markers ( |
Details
Dataframes A
and B
must consists of three columns labeled "PA1", "PA2" (coordinates of the first and second principal axis) and a column "strings" with the labels for the coordinates.
Dataframe B
is optional. If it is not specified, a biplot with a single set of markers is constructed, for which the row settings must be specified.
Value
A ggplot2 object
Author(s)
Jan Graffelman (jan.graffelman@upc.edu)
References
Graffelman, J. and De Leeuw, J. (2023) On the visualisation of the correlation matrix. Available online. doi:10.48550/arXiv.2211.13150
See Also
Examples
data("HeartAttack")
X <- as.matrix(HeartAttack[,1:7])
n <- nrow(X)
Xt <- scale(X)/sqrt(n-1)
res.svd <- svd(Xt)
Fs <- sqrt(n)*res.svd$u # standardized principal components
Gp <- crossprod(t(res.svd$v),diag(res.svd$d)) # biplot coordinates for variables
rows.df <- data.frame(Fs[,1:2],as.character(1:n))
colnames(rows.df) <- c("PA1","PA2","strings")
cols.df <- data.frame(Gp[,1:2],colnames(X))
colnames(cols.df) <- c("PA1","PA2","strings")
ggbplot(rows.df,cols.df,xlab="PA1",ylab="PA2",main="PCA")