Adding labels to my geom_bar() plot

I am currently struggling with my output of a plot. I want to display the distribution of gender in different groups. I have succeeded in plotting this.
I don't seem to succeed in adding the right labels to the plot... For instance: I want to label the red and blue charts as man/woman (where they're now labeled as 1 or 2).I have already labeled these in my script. I also want to label each group (now labeled as 10, 38, 51, etc.) at the top of each chart. Does anyone know how I could fix this? Thanks in advance!

My script so far:

Dataframe$gender <- factor(Dataframe$gender)
labels=c("man", "woman", "else")

ggplot(Dataframe, aes(x = gender, fill = gender)) +
geom_bar() + facet_wrap(~zkh)

The plot:
Schermafbeelding 2022-08-26 om 12.32.40

Hi! Could it be that you just closed the parenthesis too early? Does this work:

Dataframe$gender <- factor(Dataframe$gender,
                           labels=c("man", "woman", "else"))

Since I'm assuming you mean to pass levels and labels as arguments to the factor() function, but the way your code is written now you are defining them as variables outside the factor() function.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.