我有以下数据:
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)))
我使用geom_bar
绘图:
require(ggplot2)
ggplot(df,aes(x=sample,y=count,fill=type))+geom_bar(stat="identity",position="dodge")+theme(legend.position="none")
我的问题是如何在每个栏顶部添加df$type
作为标签?
添加:
geom_text(aes(label=type,hjust=0),position=("dodge"))
显然不起作用