r - How to label a barplot bar with positive and negative bars with ggplot2 -


i'm trying plot labeled barplot ggplot2 positive , negative bars. works far, set label outside of bar, above or under bar. tried set adjustment in vjust = c(x1,...,xn) x positive or negative value according value of bar in geom_text(). doesn't work. got error message error: "when setting aesthetics, may take 1 value. problems: vjust"

with normal plot command works. want replicate command in ggplot2:

xpos <- barplot(d, col=mycols, main='verteilung in dresden 2004',          ylab='anteil in %', xlab='milieu', names.arg=l,           cex.axis=0.7, cex.names=0.7, ylim=c(0,max(d)+0.05)) boxed.labels(xpos,d+0.02,sprintf('%d%s', d*100, '%'),           bg='transparent', border=false, cex=0.7) 

so looks in nice... ;-)

does have suggestions?

thank's y'all help.

this trick

library(plyr) library(ggplot2) library(scales) dtf <- data.frame(x = c("etb", "pma", "per", "kon", "tra",                    "ddr", "bum", "mat", "hed", "exp"),                   y = c(.02, .11, -.01, -.03, -.03, .02, .1, -.01, -.02, 0.06)) ggplot(dtf, aes(x, y)) +   geom_bar(stat = "identity", aes(fill = x), legend = false) +    geom_text(aes(label = paste(y * 100, "%"),                vjust = ifelse(y >= 0, 0, 1))) +   scale_y_continuous("anteil in prozent", labels = percent_format()) +   opts(axis.title.x = theme_blank()) 

enter image description here


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -