Skip to content
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

facet_wrap ? #42

Open
ertamaki opened this issue Apr 9, 2021 · 5 comments
Open

facet_wrap ? #42

ertamaki opened this issue Apr 9, 2021 · 5 comments

Comments

@ertamaki
Copy link

ertamaki commented Apr 9, 2021

Is there an equivalent for facet_wrap?

@tashapiro
Copy link

I was browsing for a similar answer earlier. I discovered you can use ggplot's facet_wrap function in combination with ggradar to produce facets:

ggradar()+
facet_wrap(vars(group))

@nickschurch
Copy link

How do you provide the grouping info though? When I try to provide a dataframe with a samples column and a group column, I get the error:

Error in FUN(X[[i]], ...) :
only defined on a data frame with all numeric-alike variables
6.
stop("only defined on a data frame with all numeric-alike variables")
5.
FUN(X[[i]], ...)
4.
lapply(args, function(x) {
x <- as.matrix(x)
if (!is.numeric(x) && !is.logical(x) && !is.complex(x))
stop("only defined on a data frame with all numeric-alike variables") ...
3.
Summary.data.frame(structure(list(na = c(4.58, 13.45, 8.35, 8.58,
7.76, 11.6, 3.91, 3.04, 4.1, 2.9, 5.17, 3.44, 6.93, 1.9, 10.35,
8.58, 9.72, 7.01, 1.5, 1.98, 2.11, 3.13, 1.47, 1.12, 0.98, 1.21,
1.04, 1.63, 1.49, 1.34, 2.51, 1.78, 2.81, 2.61, 2.12, 2.72, 3.14, ...
2.
ggradar(., grid.min = 0, grid.max = 100)
1.
data %>%
ggradar(grid.min = 0, grid.max = 100)

@williamlai2
Copy link

Was there an answer to this? I have a similar issue:

mtcars_radar <- mtcars %>% 
  tibble::as_tibble(rownames = "group") %>% 
  dplyr::mutate_at(vars(-group), scales::rescale) %>% 
  tail(4) %>% 
  dplyr::select(1:10)

ggradar::ggradar(mtcars_radar) +
  ggplot2::facet_wrap(vars(group))

Error in combine_vars():
! At least one layer must contain all faceting variables: group
x Plot is missing group
x Layer 1 is missing group
x Layer 2 is missing group
x Layer 3 is missing group
x Layer 4 is missing group
x Layer 5 is missing group
x Layer 6 is missing group
x Layer 7 is missing group
x Layer 8 is missing group
x Layer 9 is missing group
x Layer 10 is missing group
x Layer 11 is missing group
x Layer 12 is missing group
x Layer 13 is missing group
Run rlang::last_trace() to see where the error occurred.

Backtrace:
     x
  1. +-base (local) `<fn>`(x)
  2. \-ggplot2:::print.ggplot(x)
  3.   +-ggplot2::ggplot_build(x)
  4.   \-ggplot2:::ggplot_build.ggplot(x)
  5.     \-layout$setup(data, plot$data, plot$plot_env)
  6.       \-ggplot2 (local) setup(..., self = self)
  7.         \-self$facet$compute_layout(data, self$facet_params)
  8.           \-ggplot2 (local) compute_layout(..., self = self)
  9.             \-ggplot2::combine_vars(data, params$plot_env, vars, drop = params$drop)
 10.               \-cli::cli_abort(...)
 11.                 \-rlang::abort(...)
> packageVersion("ggradar")
[1] ‘0.2’
> packageVersion("ggplot2")
[1] ‘3.5.0’

@Iaguilaror
Copy link

Iaguilaror commented Jul 18, 2024

Same error. Here is the code:

radar2 <- radar1 +
ggtitle( "Diferencias en las Evoluciones de Eevee" ) +
scale_color_manual( values = miscolores ) +
facet_wrap( ~ name )

radar2

`

radar2
Error in combine_vars():
! At least one layer must contain all faceting variables:
group
✖ Plot is missing group
✖ Layer 1 is missing group
✖ Layer 2 is missing group
✖ Layer 3 is missing group
✖ Layer 4 is missing group
✖ Layer 5 is missing group
✖ Layer 6 is missing group
✖ Layer 7 is missing group
✖ Layer 8 is missing group
✖ Layer 9 is missing group
✖ Layer 10 is missing group
✖ Layer 11 is missing group
✖ Layer 12 is missing group
✖ Layer 13 is missing group
Run rlang::last_trace() to see where the error occurred.
`

Session info:

`

session_info()
─ Session info ───────────────────────────────────────────────────
setting value
version R version 4.3.2 (2023-10-31 ucrt)
os Windows 11 x64 (build 22631)
system x86_64, mingw32
ui RStudio
language (EN)
collate Spanish_Mexico.utf8
ctype Spanish_Mexico.utf8
tz America/Mexico_City
date 2024-07-17
rstudio 2023.12.1+402 Ocean Storm (desktop)
pandoc NA

Packages ───────────────────────────────────────────────────────
package * version date (UTC) lib source
bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.2)
bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.2)
cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.2)
callr 3.7.6 2024-03-25 [1] CRAN (R 4.3.3)
cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.2)
colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.2)
crayon 1.5.3 2024-06-20 [1] CRAN (R 4.3.3)
curl 5.2.0 2023-12-08 [1] CRAN (R 4.3.2)
desc 1.4.3 2023-12-10 [1] CRAN (R 4.3.2)
devtools * 2.4.5 2022-10-11 [1] CRAN (R 4.3.3)
digest 0.6.36 2024-06-23 [1] CRAN (R 4.3.3)
dplyr * 1.1.4 2023-11-17 [1] CRAN (R 4.3.2)
ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.2)
fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.2)
farver 2.1.2 2024-05-13 [1] CRAN (R 4.3.3)
fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.2)
forcats 1.0.0 2023-01-29 [1] CRAN (R 4.3.3)
fs 1.6.4 2024-04-25 [1] CRAN (R 4.3.3)
generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.2)
ggplot2 * 3.5.1 2024-04-23 [1] CRAN (R 4.3.3)
ggradar * 0.2 2024-07-18 [1] Github (f99517a)
glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.2)
gtable 0.3.5 2024-04-22 [1] CRAN (R 4.3.3)
htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.2)
htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.3.3)
httpuv 1.6.14 2024-01-26 [1] CRAN (R 4.3.2)
labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.1)
later 1.3.2 2023-12-06 [1] CRAN (R 4.3.2)
lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.2)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.2)
memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.2)
mime 0.12 2021-09-28 [1] CRAN (R 4.3.1)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.3.3)
munsell 0.5.1 2024-04-01 [1] CRAN (R 4.3.3)
pacman * 0.5.1 2019-03-11 [1] CRAN (R 4.3.3)
pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.2)
pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.3.3)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.2)
pkgload 1.4.0 2024-06-28 [1] CRAN (R 4.3.3)
processx 3.8.4 2024-03-16 [1] CRAN (R 4.3.3)
profvis 0.3.8 2023-05-02 [1] CRAN (R 4.3.3)
promises 1.2.1 2023-08-10 [1] CRAN (R 4.3.2)
ps 1.7.7 2024-07-02 [1] CRAN (R 4.3.3)
purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.2)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.2)
ragg 1.3.2 2024-05-15 [1] CRAN (R 4.3.3)
RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.3.1)
Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.3.2)
remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.3.2)
rlang 1.1.4 2024-06-04 [1] CRAN (R 4.3.3)
rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.2)
scales 1.3.0 2023-11-28 [1] CRAN (R 4.3.2)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.3)
shiny 1.8.0 2023-11-17 [1] CRAN (R 4.3.2)
stringi 1.8.3 2023-12-11 [1] CRAN (R 4.3.2)
stringr 1.5.1 2023-11-14 [1] CRAN (R 4.3.2)
systemfonts 1.1.0 2024-05-15 [1] CRAN (R 4.3.3)
textshaping 0.3.7 2023-10-09 [1] CRAN (R 4.3.3)
tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.2)
tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.3.3)
tzdb 0.4.0 2023-05-12 [1] CRAN (R 4.3.2)
urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.3.3)
usethis * 2.2.3 2024-02-19 [1] CRAN (R 4.3.3)
utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.2)
vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.2)
vroom * 1.6.5 2023-12-05 [1] CRAN (R 4.3.2)
withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.2)
xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.2)

[1] C:/Users/iaguilar/AppData/Local/R/win-library/4.3
[2] C:/Program Files/R/R-4.3.2/library
`

Thanks for your time.

@jczimm
Copy link

jczimm commented Jan 9, 2025

@williamlai2 From inspecting the returned gg object, I found a workaround (I only switched away from mutate_at because it was superceded):

mtcars_radar <- mtcars %>% 
  tibble::as_tibble(rownames = "group") %>% 
  dplyr::mutate(across(-group, scales::rescale)) %>% 
  tail(4) %>%
  dplyr::select(1:10)
ggradar::ggradar(mtcars_radar) +
  ggplot2::facet_wrap(~`Group.1`)

The key is that from ggplot's perspective, the grouping variable is actually named "Group.1" (source).

> R.version.string
[1] "R version 4.2.3 (2023-03-15 ucrt)"
> packageVersion("tibble")
[1] ‘3.2.1’
> packageVersion("dplyr")
[1] ‘1.1.1’
> packageVersion("ggradar")
[1] ‘0.2’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants