r - how I can make a plot with two variable like the one in the picture -


i have data frame i have data frame

i want make plot ggplot2 i want make plot ggplot2

which function should use? or name of plot

this give similar plot.

library(ggplot2) library(ggrepel)  #sample data df <- data.frame(age_range = c('m.25-34', 'm.18-24', 'm.13-17', 'f.25-34', 'f.18-24', 'f.13-17'),                  count = c(3356, 2071, 15, 5619, 4342 ,29))  #pre-process dataframe can used ggplot2 df$sex <- gsub('(\\s).*', '\\1',df$age_range) df$age <- gsub('\\s{2}(.*)', '\\1',df$age_range)  #plot ggplot(df, aes(x= age, y= (count/sum(count))*ifelse(sex=="f",1,-1), fill=sex)) +    geom_bar(stat="identity", position = "identity") +   geom_text_repel(aes(y = (count/sum(count))*ifelse(sex=="f",1,-1), label=paste0(round(count/sum(count)*100, digits = 2),"%"))) +   ylab("your fans") +   ggtitle("the people page") +   theme(axis.text.y=element_blank()) 


hope helps!


Comments