I have this data frame
I want to make a plot like it with ggplot2
which function should i use? or what the name of this plot
I have this data frame
I want to make a plot like it with ggplot2
which function should i use? or what the name of this plot
This will give you a 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 so that it can be used with 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 who like your Page") +
theme(axis.text.y=element_blank())
Hope this helps!