-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use facet_matrix
's labels in aes()
#255
Comments
With some mathematics you should be able to target each row |
Oh that is some nice magic. If anyone ever comes looking here...: library(ggplot2)
library(ggforce)
p <- ggplot(mtcars) +
geom_point(aes(.panel_x, .panel_y)) +
facet_matrix(vars(mpg, am, cyl, carb), vars(am, cyl, hp))
factor_to_row <- function(f, nrow) {
ncol <- max(as.numeric(f)) / nrow
factor((as.numeric(f) - 1) %/% ncol)
}
factor_to_col <- function(f, ncol) {
factor((as.numeric(f) - 1) %% ncol)
}
p + aes(shape = factor_to_row(PANEL, 4))
#> Warning in rows == cols: longer object length is not a multiple of shorter
#> object length p + aes(shape = factor_to_col(PANEL, 3))
#> Warning in rows == cols: longer object length is not a multiple of shorter
#> object length Created on 2022-08-31 by the reprex package (v2.0.1) |
Yes!! This is everything I needed! Please do not ever remove this @thomasp85 🙏🏾 I've been struggling for hours now, and this ( EDIT: If anyone comes looking for this.... this is how I accomplished my use-case of coloring specific plots' points and trend lines different colors: Summary Code:
Mapping colors to plots on the
Output: |
I'd like the have shapes vary by the rows of a
facet_matrix
, is this possible? How does one access the x/y panel ID?The text was updated successfully, but these errors were encountered: