View source: R/convert2ggplot.r
convert2ggplot | R Documentation |
Function attempts to coerce plot information from an RRPP plot object to an amenable ggplot object.
convert2ggplot(object)
object |
A plot object produced from |
This function will attempt to use the plot arguments from an RRPP plot object
to make a ggplot that can be additionally updated, as desired. Not all plot
characteristics can be converted. For example, text arguments are not currently
passed to ggplot
, as the text
function and geom_text
arguments do not easily align. However, one can use text arguments produced by
a RRPP plot object and geom_text to augment a ggplot object the way they like.
This function assumes no responsibility for arguments made by ggplot
.
It merely produces a ggplot object that should resemble an RRPP plot default. Any
augmentation of ggplot objects can be done either by direct intervention of the ggplot
produced or reformatting the initial RRPP plot produced. One should not expect direct
correspondence between R base plot parameters and ggplot parameters. For example,
error bars will generally appear as different widths, without an easy way to control them,
changing from one format to the other.
Michael Collyer
## Not run:
### Linear Model Example
data(Pupfish)
fit <- lm.rrpp(coords ~ log(CS) + Sex*Pop, SS.type = "I",
data = Pupfish, print.progress = FALSE)
# Predictions (holding alternative effects constant)
shapeDF <- expand.grid(Sex = levels(Pupfish$Sex),
Pop = levels(Pupfish$Pop))
rownames(shapeDF) <- paste(shapeDF$Sex, shapeDF$Pop, sep = ".")
shapePreds <- predict(fit, shapeDF)
summary(shapePreds, PC = TRUE)
# Plot prediction
P <- plot(shapePreds, PC = TRUE, ellipse = TRUE)
convert2ggplot(P)
### Ordination Example
data("PlethMorph")
Y <- as.data.frame(PlethMorph[c("TailLength", "HeadLength",
"Snout.eye", "BodyWidth",
"Forelimb", "Hindlimb")])
Y <- as.matrix(Y)
R <- lm.rrpp(Y ~ SVL, data = PlethMorph,
print.progress = FALSE)$LM$residuals
# PCA (on correlation matrix)
PCA.ols <- ordinate(R, scale. = TRUE)
PCA.ols$rot
prcomp(R, scale. = TRUE)$rotation # should be the same
PCA.gls <- ordinate(R, scale. = TRUE,
transform. = FALSE,
Cov = PlethMorph$PhyCov)
P <- plot(PCA.gls)
convert2ggplot(P)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.