Im trying to get a figure of different variables (strategy) in to age groups (young vs old) in two gender group (female and male). I have a data of these variables. I uploaded them in R, and created a dataframe for them following this format:
crosstab <- xtabs(~strategy+age+gender, data = data2)
crosstab
tabframe <- as.data.frame(crosstab)
tabframe
so i have 20 observations in 4 variables (strategy, age, gender, Frequency).
Now when I plot it following the below code, I got a figure for 4% not 100%! and y is showing up with (counts) not (percentage) as Im expecting it.
rf <- ggplot(data = data2) +
geom_bar(
mapping = aes(x = age,
fill =strategy,
),
position = position_dodge2(width = 0.9, preserve = "single"),
colour="black"
) +
scale_y_continuous(labels = percent_format())+
facet_grid(~gender, labeller = labeller(gender = saud_gender_names, task = saud_task_names)) +
scale_fill_manual(values=cbPalette)+
scale_colour_manual(values=cbPalette)+
theme_bw() +
scale_x_discrete(labels=c("younger", "older")) +
ggtitle("contour choice in ynqs")
rf
This is the photo I got
Can you help me solving this problem?
Best
I have tried to change many dataframe but it doesn't work