I have the following data:
set.seed(1)
df <- data.frame(type=c("A","B","D","A","C","D","B","C","D","E"),
count=as.integer(runif(10,100,200)),
sample=c(1,1,1,2,2,2,3,3,3,3),stringsAsFactors=F)
df$type <- factor(df$type,levels=unique(sort(df$type)))
which I plot using geom_bar
:
require(ggplot2)
ggplot(df,aes(x=sample,y=count,fill=type))+geom_bar(stat="identity",position="dodge")+theme(legend.position="none")
My question is how to add df$type
as a label on top of each bar?
Adding:
geom_text(aes(label=type,hjust=0),position=("dodge"))
obviously doesn't work