Without a reproducible example, it is difficult to be sure that this answer will fit to your dataset.
Here, based on few informations you provided, I generate a fake example:
df <- data.frame(Donation = sample(1:20, 100, replace = TRUE),
Treatment = sample(c("TG1","TG2"), 100, replace = TRUE),
Category = sample(c("Teenager","Adult"), size = 100, replace = TRUE))
Donation Treatment Category
1 2 TG2 Adult
2 6 TG2 Adult
3 11 TG1 Teenager
4 16 TG2 Adult
5 7 TG1 Teenager
6 17 TG2 Adult
You can use dplyr
to compute the sum of donation per treatment group and category as follow:
library(dplyr)
DF <- df %>% group_by(Treatment, Category) %>%
summarise(Sum = sum(Donation))
# A tibble: 4 x 3
# Groups: Treatment [2]
Treatment Category Sum
<fct> <fct> <int>
1 TG1 Adult 207
2 TG1 Teenager 236
3 TG2 Adult 372
4 TG2 Teenager 235
Then, you can use this new dataframe "DF" to get bargraph using ggplot2
:
library(ggplot2)
ggplot(DF, aes(x = Treatment, y = Sum, fill = Category))+
geom_col(position = position_dodge())

EDIT: Separating bargraph
To get only the sum of Donation per treatment group:
ggplot(DF, aes(x = Treatment, y = Sum, fill = Treatment))+
geom_col()

To get only the sum of Donation per category:
ggplot(DF, aes(x = Category, y = Sum, fill = Category))+
geom_col()
