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

distinguish groups and facets #410

Closed
CorradoLanera opened this issue Apr 10, 2020 · 2 comments
Closed

distinguish groups and facets #410

CorradoLanera opened this issue Apr 10, 2020 · 2 comments
Labels
enhancement 🔥 New feature or request

Comments

@CorradoLanera
Copy link

Describe the solution you'd like

Suppose you have data like the following one

requireNamespace("tidyr")
requireNamespace("dplyr")
library(ggstatsplot)

sample_data <- tidyr::crossing(
  time     = factor(1:3),
  group    = letters[7:8],
  type     = LETTERS[1:4],
  value_id = 1:100
) %>% 
  dplyr::mutate(value = runif(row_number()))

I really love to obtain an enriched {ggstatsplot} for something like this:

sample_data %>% 
  ggplot(aes(x = time, y = value, colour = group)) +
  geom_violin() +
  facet_wrap(type ~ .)

My first (not working) attempt was

grouped_ggbetweenstats(
  data = sample_data,
  x = time,
  y = value,
  group = group, # {{!! I miss this one !!}}
  grouping.var = type,
  title.prefix = "Type",
  type = "np",
  pairwise.comparisons = TRUE, # between groups/value_id each time
  pairwise.annotation = "p.value",
  message = FALSE,
  title.text = "Differences in values by month (against groups) each type."
)

How could we do it?

I do not know if there is a workaround to achieve the expected result.
If I have to throw an idea, the only one I have in mind is not reliable (because it brakes to many things inside the package conventions):

Include the option grouping.var in ggbetweenstats() for groups (with comparisons made between groups) rename grouped_ggbetweenstats(), to facet_ggbetweenstats() including the option facet.var.

Note

I am not able to achieve it neither if I do not have "types": suppose there is a single type (ie no facet), how can I show the variation of groups comparison along time? If this is possible (and I have missed it), next, I have no problem to produce a distinct plot each type.

sample_data %>% 
  ggplot(aes(x = time, y = value, colour = group)) +
  geom_violin()
@IndrajeetPatil IndrajeetPatil added the enhancement 🔥 New feature or request label Apr 10, 2020
@CorradoLanera
Copy link
Author

CorradoLanera commented Apr 10, 2020

This could show the expected result (and why it is suboptimal :-))

sample_data <- tidyr::crossing(
  time     = 1:3,
  group    = factor(letters[7:8]),
  type     = factor(LETTERS[1:4]),
  value_id = 1:100
) %>%
  dplyr::mutate(value = runif(dplyr::row_number()))


p_list <- sample_data %>%
dplyr::group_by(.data = ., type) %>%
  dplyr::group_map(
    .f = ~ grouped_ggbetweenstats(
      data = .,
      x = group,
      y = value,
      plotgrid.args = list(
        align = "h",
        ncol = length(unique(sample_data[["time"]]))
      ),
      grouping.var = time,
      title.prefix = "time",
      type = "np",
      pairwise.comparisons = TRUE, # between groups/value_id each time
      pairwise.annotation = "p.value",
      message = FALSE
    )
  )

# combining plots
cowplot::plot_grid(
  plotlist = p_list,
  labels = levels(sample_data[["type"]]),
  align = "v",
  nrow = nlevels(sample_data[["type"]])
)

grouped-faced-ggstatsplot

@IndrajeetPatil
Copy link
Owner

Closing in favor of #500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🔥 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants