tags:

views:

349

answers:

1

I am looking for the way to annotate axis in ggplot2. The example of the problem can be found here: http://learnr.wordpress.com/2009/09/24/ggplot2-back-to-back-bar-charts.

The y axis of the chart (example graph in the link) has an annotation: (million euro). Is there a way to create such types of annotations in ggplot2? Looking at the documentation there is no obvious way, since the ggplot does not explicitly let you put objects outside plotting area. But maybe there is some workaround?

One of the possible workarounds I thought about is using scales:

data=data.frame(x=1:10,y=1:10)
qplot(x=x,y=y,data=data)+scale_y_continuous(breaks=10.1,label="Millions")

But then how do I remove the tick? And it seems that since ggplot does not support multiple scales, I will need to grab the output of the scale_y_continuous, when it calculates the scales automaticaly and then add my custom break and label by hand. Maybe there is a better way?

+3  A: 

Maybe grid.text():

grid.text("label", x = unit(xpos, "npc"), y = unit(ypos, "npc"))

with appropriate values for xpos and ypos.

rcs
Yes, but how do I calculate values xpos and ypos automaticaly? Or how to adapt this with faceting? Of course it is nice hack, but still too complicated, since to get useful implementation, I see that I will still need to delve deeply into ggplot code.
mpiktas