Add Labels ggplot2
How to add labels by a seperate vector on geom_bar() plot?
a<-as.POSIXlt("2013-07-01 00:00:00",origin = "1960-01-01",tz="GMT")
b<-as.POSIXlt("2013-07-08 00:00:00",origin = "1960-01-01",tz="GMT")
week1<-sample(seq(as.numeric(a),by=60*60,length.out=200),200,T)
week2<-sample(seq(as.numeric(b),by=60*60,length.out=200),200,T)
times<-c(week1,week2)
class(times)<-c("POSIXt","POSIXct")
times<-as.POSIXlt(times,origin = "1960-01-01",tz="GMT")
key<-sample(LETTERS[1:3],200,T)
df<-data.frame(times=times,order=factor(rep(1:2,each=100)), key=key)
p<-ggplot(df, aes(x=key, y=..count.. ,fill=key ) )
p<-p + geom_bar()
p<-p + facet_wrap( ~ order,ncol=2)
p<-p + coord_flip()
p
I like to add the number of each key value, which is represented by df1$y:
df1<-ddply(df, .(key,order), summarize, y=length(key))
p<-p + geom_text(aes(label=df$1y), vjust=0)
No comments:
Post a Comment