2

I've looked for an answer to this, but have not found one - I use ggplot2 to draw a series of densities after I draw them, I need to obtain the x and y scales, so that I can annotate in the upper left corner - here is my code:

gg= qplot(ExpRef,geom='density',color=IOL,fill=IOL,alpha=0.8,data=tmp2,
        main=mtitle,xlab ="Expected Refraction",cex.axis=3.0,font.axis = 2)  #bold and cesx = multiplier);
ggp = gg + geom_vline(data=data.frame(x=0,y=0),xintercept=means, lwd= 2,color=I("red")) ;
ggp = gg + geom_vline(data=data.frame(x=0,y=0),xintercept=PlanRef, lwd= 2,color=I("green")) ;
ggp = ggp + annotate("text",x=PlanRef, y = 1,  label=paste('Planned Refraction'),angle=90,size=7.0,colour='black', hjust = 0, vjust = 0)

ggp = ggp + annotate("text",x=SRKTRef, y = 0,label=paste('SRKT IOL-->'),angle=90,size=6.0,colour='yellow', hjust = 0, vjust = 0);
  • So in the last line I need to know the max of y to place the annotation in the upper part of the graphic - is there a way to get the scales that were computed in the density graph layer? thanks
4

1 回答 1

3

对于绘图区域边界处的注释,您可以使用-Inf(左/下)或+Inf(右/上):

qplot(1:10, rnorm(10)) + 
annotate("text", x=Inf, y=-Inf, 
         label="bottom-right", vjust=-0.5, hjust=1)
于 2013-05-13T16:01:15.377 回答