I have the following issue with labeling the smaple size in my dataset:
library(ggplot2)
library(EnvStats)
library(tidyverse)
cars_pre= mtcars %>% mutate(time="Pre")
cars_post= mtcars %>% mutate(time="Post")
df= rbind(cars_pre,cars_post)
p <- ggplot(df, aes(x = factor(cyl), y = mpg, fill = time) +
theme(legend.position = "none"))
ggplot(df, aes( factor(cyl), mpg)) + geom_boxplot(aes(fill = time) ) +
stat_n_text()
The issue I have is that I have pre/post groups: but those are the same subjects, so when I plot stat_n_text
it doubles my sample size, cause it adds pre and post samples together ( treats them as separate subjects). Is there a way to update the n
, so it will be half of its value (in a picture I want n =11, 7 and 14 for cyl 4,5, and 6 respectively)?