当我使用ggplot2包绘制具有无穷大值的线时,即使我使用了较大的“ nudge_y”参数,也无法完全显示其标签。手动文本可以得到结果,但这不是我的答案。如何完整显示?
x=seq(1,3,1) y=c(1/3,Inf,3/3) dt=data.frame(x=x,y=y,z=round(y,2)) ggplot(dt)+geom_line(aes(x=x,y=y))+ geom_text(aes(x=x,y=y,label=z))
https://i.stack.imgur.com/kEs3d.png
您可以添加+ coord_cartesian(clip = "off")以显示被剪裁超出绘图区域的部分。
+ coord_cartesian(clip = "off")