Learn R Programming

Momocs (version 1.2.9)

plot_PCA: Multivariate plots using grindr layers

Description

Quickly vizualise PCA objects and friends (LDA) and build customs plots using the layers. See examples.

Usage

plot_PCA(x, f, axes = c(1, 2), palette = pal_qual, points = TRUE,
  points_transp = 1/4, morphospace = TRUE, morphospace_position = "range",
  chull = TRUE, chullfilled = FALSE, center_origin = TRUE, zoom = 0.9,
  eigen = TRUE, box = TRUE, axesnames = TRUE, axesvar = TRUE)

Arguments

x

PCA object

f

factor. A column name or number from $fac, or a factor can directly be passed. Accept numeric as well.

axes

numeric of length two to select PCs to use (c(1, 2) by default)

palette

color palette to use col_summer by default

points

logical whether to draw this with layer_points

points_transp

numeric to feed layer_points (default:0.25)

morphospace

logical whether to draw this using layer_morphospace

morphospace_position

to feed layer_morphospace (default: "range")

chull

logical whether to draw this with layer_chull

chullfilled

logical whether to draw this with layer_chullfilled

center_origin

logical whether to center origin

zoom

numeric zoom level for the frame (default: 0.9)

eigen

logical whether to draw this using layer_eigen

box

logical whether to draw this using layer_box

axesnames

logical whether to draw this using layer_axesnames

axesvar

logical whether to draw this using layer_axesvar

See Also

Other grindr: drawers, layers, mosaic_engine, papers, pile

Examples

Run this code
# NOT RUN {
### First prepare two PCA objects.

# Some outlines with bot
bp <- bot %>% mutate(fake=sample(letters[1:5], 40, replace=TRUE)) %>%
efourier(6) %>% PCA
plot_PCA(bp)
plot_PCA(bp, ~type)
plot_PCA(bp, ~fake)

# Some curves with olea
op <- olea %>%
mutate(s=coo_area(.)) %>%
filter(var != "Cypre") %>%
chop(~view) %>% lapply(opoly, 5, nb.pts=90) %>%
combine %>% PCA
op$fac$s %<>% as.character() %>% as.numeric()

op %>% plot_PCA

### Now we can play with layers
# and for instance build a custom plot
# it should start with plot_PCA()

my_plot <- function(x, ...){

x %>%
    plot_PCA(...) %>%
    layer_points %>%
    layer_ellipsesaxes %>%
    layer_rug
}

# and even continue after this function
op %>% my_plot(~var, axes=c(1, 3)) %>%
    layer_title("hi there!") %>%
    layer_stars()

# You get the idea.
# }

Run the code above in your browser using DataLab