1

Here's how I want it to look (made in Excel): excel example

And here's the template code:

library(ggplot2)
data <- c(0.3,0.4,0.5,0.6,0.7,0.8)
qplot(x=1:6, y=data, geom="bar", stat="identity")

Edited after commenter suggested I need more words in my question:

My code above draws the x-axis at y=0 so that all the bars go up from the axis. I want the x-axis to be at y=0.5 and I want bars with values < 0.5 to go down, while bars with values > 0.5 to go up. Like in the Excel plot I have placed above.

Hopefully this makes sense.

yoavram
  • 4,289
  • 3
  • 21
  • 21
  • 1
    qplot(x=1:6, y=data - 0.5, geom="bar", stat="identity") + scale_x_reverse(). ggplot tries to save the world from the most extreme scaling abuses. I don't think you can do what you really want to do without showing it on the axis. – Ido Tamir May 14 '13 at 07:57
  • Please see the response by @AriB.Friedman in [this answer](http://stackoverflow.com/a/11398481/1492421) – Ricardo Saporta May 14 '13 at 08:20
  • I've edited my question per @RicardoSaporta's comment – yoavram May 17 '13 at 08:24
  • @IdoTamir - your answer is not enough, I want to re-label the y-ticks so that it will go from 0 to 1, not from -0.5 to 0.5. Thanks though! – yoavram May 17 '13 at 08:27
  • Its not an answer, its a comment. Your values are positive. Why do you lie to the reader that they are negative? Rescale your values and then you don't lie. – Ido Tamir May 17 '13 at 11:27
  • Sorry, I meant your comment. I'm not lying. The baseline result is 0.5 and I want to show which categories give a result of < 0.5 and which give a result of > 0.5. A horizontal line is nice but it is more clear when some bars go up and some go down. – yoavram May 19 '13 at 06:44

1 Answers1

1

It is a little fiddly, but possible:

qplot(x=factor(1:6,levels=6:1), y=data-0.5, geom="bar", stat="identity") + scale_y_continuous(breaks=seq(-0.5,0.5,0.1),labels=seq(0,1,0.1),limits=c(-0.5,0.5))
James
  • 65,548
  • 14
  • 155
  • 193
  • Thanks. Here's the [final code](https://gist.github.com/yoavram/5606906) and the [final plot](http://i.imgur.com/S6l1XNK.png). – yoavram May 19 '13 at 06:47