我一直在寻找这个问题的答案,但还没有找到 - 我使用ggplot2绘制一系列密度 绘制它们后,我需要获取 x 和 y 比例,以便我可以在左上角进行注释 - 这是我的代码:
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);
- 因此,在最后一行中,我需要知道 y 的最大值,以将注释放置在图形的上部 - 有没有办法获取在密度图层中计算的比例? 谢谢
最佳答案
对于绘图区域边界的注释,您可以使用-Inf
(左/下)或+Inf
(右/上):
qplot(1:10, rnorm(10)) +
annotate("text", x=Inf, y=-Inf,
label="bottom-right", vjust=-0.5, hjust=1)
关于r - 生成初始绘图层后如何在 ggplot 中获取比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525299/