I have a data similar to this one:
my_data <- tibble(flower_color = c(rep("blue", 12), rep("red", 34), rep("pink", 19)),
flower_length = c(rep("short", 4), rep("medium", 15), rep("long", 12),
rep("very long", 34)))
My aim is to create a stacked barplot representation, like this one:
table(my_data$flower_color, my_data$flower_length) %>%
as.data.frame() %>%
filter(Freq > 0) %>%
ggplot(aes(x = Var1, y = Freq, fill = Var2)) +
geom_bar(position = "fill", stat = "identity") +
scale_y_continuous(labels = scales::percent_format()) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
set_palette(q, "jco") +
#stat_compare_means() +
# Global p-value
stat_compare_means(ref.group = "0.5", label = "p.signif",
label.y = c(22, 29))
My questions are:
- I would like to show on top of each bar the sample size for each blue, pink and red (e.g. on top of blue flower bar adding 12).
- Any suggestion about which statistical test I should use for checking if significant differences are present? And How can I add these results on my plot?
