注释标签在GGPLOT2中剪辑
我正在努力避免被剪切的底部注释。被砍掉的是“ P”上的下降。我在vjust上使用了“内向”选项。
df <- data.frame(x=c(as.Date("2020-01-01"),as.Date("2022-01-01"))
,y=c(0,1))
df
ggplot(df) +
geom_point(mapping=aes(x=x,y=y)) +
annotate("text",x=mean(df$x),y=-Inf,label="Clipped",hjust=0.5,vjust="inward",size=12,colour="red") +
annotate("text",x=mean(df$x),y=Inf,label="Not Clipped",hjust=0.5,vjust="inward",size=12,colour="blue")
I'm trying to avoid the bottom annotation being clipped. It's the descender on the "p" that gets chopped off. I've used the "inward" option on vjust.
df <- data.frame(x=c(as.Date("2020-01-01"),as.Date("2022-01-01"))
,y=c(0,1))
df
ggplot(df) +
geom_point(mapping=aes(x=x,y=y)) +
annotate("text",x=mean(df$x),y=-Inf,label="Clipped",hjust=0.5,vjust="inward",size=12,colour="red") +
annotate("text",x=mean(df$x),y=Inf,label="Not Clipped",hjust=0.5,vjust="inward",size=12,colour="blue")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不希望将其夹在相同的位置上,则可以使用
coord_cartesian(clip =“ off”)
:在2022-07-02创建的 reprex软件包(v2.0.1)
If you don't want it to be clipped on the same position, you can use
coord_cartesian(clip = "off")
:Created on 2022-07-02 by the reprex package (v2.0.1)
一种可能的方法是使用
min
和max
y值:在2022-07-02创建的 reprex软件包(v2.0.1)
A possible approach would be to use the
min
andmax
y values:Created on 2022-07-02 by the reprex package (v2.0.1)
有趣的。看来此问题与选择的基本线路对齐文本标签有关。切换到
geom_label
时,可以清楚地看到这一点,在其中我们看到,对于剪辑标签,为对齐方式选择的基本线并不是“ p”的末端。因此,“ p” s被删除:一个可能的修复是切换到
ggtext :: geomrichtext
:Interesting. Looks like this issue is related to what is chosen as the base line to align the text labels. This could be seen clearly when switching to
geom_label
where we see that for the clipped label the base line chosen for the alignment is not the end of the "p". Hence the "p"s get clipped off:One possible fix would be to switch to
ggtext::GeomRichtext
: