Hello,

I'm starting out in R and would need a little help! I am trying to make a bar graph with the average of factors.

I have 2 columns:

Col1 with qualitative values to factor : red, black, blue

Col2 with quantitative values so I want to get the average

Here is what I could initiate, but I get the global average...

library(ggplot2)

BDD$Col1 <- as.factor(BDD$Col1)

moy <- mean(BDD$Col2, na.rm = TRUE)

color_table <- data.frame(color = BDD$Col1, mean = moy)

ggplot(BDD, aes(x = Col1, fill = moy)) +

geom_bar() +

xlab("Color") +

ylab("Average by color")

With the desired result:

(aggregated) Associated mean

Red

Black

Blue

...

Thank you very much for your help!

Sincerely,