Hi,
Welcome to the RStudio community!
All you need to do is convert the 1 and 2 into factors. You can either do this by explicitly converting them using the as.factor() function, or you can use something like ifelse() as I have done below to change the numbers into names.
library(ggplot2)
set.seed(1) #Only needed for reproducibility
df = data.frame(
id = 1:10,
gender = sample(1:2, 10, replace = T),
val = runif(10)
)
df$gender = ifelse(df$gender == 1, "male", "female")
ggplot(df, aes(x = gender, y = val)) +
geom_violin()

Created on 2022-04-01 by the reprex package (v2.0.1)
Hope this helps,
PJ