r - How to add bar value to the graph? -
i have following r code generate graph of number of alerts per week. graph looks great, i'd add exact value of bar. i've been trying using geom_text, can't work. doesn't know variable ..count.. , don't know how refer value of bar otherwise.
a = c(0, 0, 0, 1, 2, 3, 3, 3) b = c(1, 1, 0, 0, 1, 1, 1, 1) sa2 = data.frame(weekofyear = a, urgentstate = b, isurgent = b) p <- qplot(factor(weekofyear), data=sa2, geom="bar", fill=factor(urgentstate), order=-as.numeric(isurgent)) p <- p + geom_bar() # p <- p + geom_text(aes(label = factor(weekofyear), y = ..count..)) doesn't work p <- p + ggtitle("number of alerts per week") p <- p + scale_x_discrete(name="week") p <- p + scale_y_continuous(name="number of alerts")
is there way add value values within bar (fill)?
p + stat_bin(aes(fill=na,label=..count..), geom="text",vjust=-1)
just leave out fill=na
if don't want numbers total bars.
Comments
Post a Comment