0

does anyone know if it's possible to plot a grouped ggbetweenstats (using grouped_ggbetweenstats) plot if some variables in my x-axis hold all zero values for some of the groupings (i.e. it cannot be plotted, but I'd like it to be left blank, or for the graph to add a boxplot/point on the zero mark for those categories)? And if so, how do I do this?

I've tried googling about it but no answers so far

  • Hi, to increase your chances of getting help it's a good idea to provide a small sample dataset and the code that you've used so far. Please read [this](https://stackoverflow.com/help/how-to-ask) and [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Andrea M Apr 02 '22 at 09:30
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 03 '22 at 06:26

1 Answers1

0

This is a relatively complex question to ask without giving any sample data, and if your data is exactly as you describe it, then it is not clear what your problem is.

Suppose we simulate some data for demonstration purposes:

library(ggstatsplot)

set.seed(1)

df <- data.frame(x = rep(paste("Class", LETTERS[1:3]), each = 20),
                 y = rnorm(60, rep(1:3, each = 20)),
                 group = rep(paste("Group", 1:2)))

This gives us 10 random values for each combination of two grouping variables, x, which we plot on the x axis, and group, which we use as the grouping variable. When we plot it looks like this:

grouped_ggbetweenstats(df, x, y, grouping.var = group)

enter image description here

Suppose now that Class B only contains 0 values, which from your description is how your own data is structured.

df$y[df$x == "Class B"] <- 0

But we can still plot the results:

grouped_ggbetweenstats(df, x, y, grouping.var = group)

enter image description here

And the zero-only variable is still plotted with a value of zero, as desired.

Is there some assumption that I have made wrongly?

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87