I'm relatively new to R and would like to ask: I have a data frame (my.data) with 2 columns: "PHENO" which is a factor with two levels (1 or 2) and "bins" which is numeric (natural number between 1 to 10). I'm trying to plot the frequency (as percents) of PHENO==2 vs the bins, where the 100% is total number observations (levels 1+2).
This is what I did, but the 100% is not all of the observations:
ggplot(data = subset(my.data, PHENO == 2)) +
geom_bar(mapping = aes(x = as.factor(bins), y = ..prop.., group = 1), stat = "count") +
scale_y_continuous(labels = scales::percent_format(), limits = c(0,0.15)) +
geom_hline(yintercept = 0.05, linetype="dashed", color = 'blue', size = 1) +
annotate(geom = "text", label = 'Prevalence 5%', x = 1.5, y = 0.05, vjust = -1, col = 'blue') +
Also, I tried to add frequency labels over the bars but it didn't work:
geom_text(aes(label = as.factor(bins)), position=position_dodge(width=0.9), vjust = -0.25)
I would appreciate your help.