fawda123 / ggord

a take on ordination plots using ggplot2
https://fawda123.github.io/ggord/
62 stars 20 forks source link

Group and facet ggord plot using separate variables #23

Closed gltyree closed 1 year ago

gltyree commented 1 year ago

Issues

I want to plot my ordination results so that they are grouped by one variable (specified with the 'grp_in' argument) and faceted by another. Is this possible for ggord? Using facet_wrap separately hasn't worked.

Here is a reproducible example using the iris dataset. I want to group my ordination results by 'Species' but facet them by 'Petal.color'.

library(ggplot2)
library(ggord)

iris$Petal.color <- as.factor(rep(c("purple", "white", "blue"), times = 50))
ord <- prcomp(iris[, 1:4])

ggord(ord, iris$Species)  # How to facet by Petal.color and not Species?? 
# ggord(ord, iris$Species) + facet_wrap(~iris$Petal.color)  ## This line returns an error message, listed below 
# Error: Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(2L, 3L, 1L, 2L,  : replacement has 150 rows, data has 168
fawda123 commented 1 year ago

@gltyree thanks for the reproducible example. Unfortunately, this is not possible in the current version. The ordination is for the whole dataset, so the only facetting variable you can use is the grouping variable.

gltyree commented 1 year ago

@fawda123 Aw, okay. Thank you for the quick reply and explanation!