I created this plot with ggplot2:

The outside lines need to correspond to the Y scale, (i.e the Y position of the lines for Text1 should be 100 and 85). The only way I can do it by drawing a blank plot to the right of the figure with the same scale as the barchart and then using annotate function to draw the lines. Another approach is to simply “manually” draw the lines with grid.lines, however the coordinates of grid.lines will not correspond to the Y scale of the plot.
Is it possible to somehow draw these lines using a different approach? I assume it would have to be done with grid.lines. How could I pass Y coordindates of the barchart to grid.lines?
Below is the minimal code used to create this figure:
library (ggplot2)
test= data.frame(
group=c(rep(1,6), rep(2,6)),
subgroup=c( 1,1,1,2,2,2,1,1,1,2,2,2),
category=c( rep(1:3, 4)),
count=c( 10,80,10,5,90,5, 10,80,10,5,90,5 )
)
qplot(subgroup,
count,
data=test,
geom="bar",
stat="identity",
fill =category,
facets = .~ group, width=0.9)+
opts(legend.position="none",
plot.margin = unit(c(0,9,2,0), "lines"))

How can I draw the lines to the right of the bars?
I recently asked a question about drawing text outside of plot area in ggplot2 and the solution was to use gt$layout and grid.draw.
Displaying text below the plot generated by ggplot2
Could the similar approach be used here? It is my understanding that annotation_custom is for text only and won’t work with other graphical elements.
Thanks
Update
The original solution used
annotation_custom, but a problem withannotation_customis that it draws the annotation in all panels. However, with a simple modification,annotation_customcan be made to draw in one panel only (taken from Baptiste’s answer here)Original Solution
I think almost any Grob created using
grid()can be used inannotation_custom().There might be neater ways to do this, but here’s a way using
grid,annotation_customand @baptiste’s code from here to override the clipping (as in the earlier post).