在 ggplot2 中重新定位散点图标签

发布于 2024-08-16 08:45:30 字数 58 浏览 1 评论 0原文

是否可以重新定位标签,使扇区 (-x,y) 中的标签位于左侧,而扇区 (+x,y) 中的标签位于右侧?

Is it possible to reposition the labels such that in sector (-x,y) the label is on the left and sector (+x,y) the label is on the right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-08-23 08:45:30

我不确定这是否是您正在寻找的:

library("ggplot2")
tmp <- data.frame(x=-5:5, y=rnorm(11), lab=LETTERS[1:11])
p <- ggplot(aes(x=x, y=y, label=lab), data=tmp) +
     geom_point() +
     geom_text(data=subset(tmp, x > 0), hjust=-0.5) +
     geom_text(data=subset(tmp, x <= 0), hjust=1.5)
print(p)

geom_text 标签 http://img8.imageshack.us /img8/1056/geomtext.png

I'm not definitely sure if this is what you were looking for:

library("ggplot2")
tmp <- data.frame(x=-5:5, y=rnorm(11), lab=LETTERS[1:11])
p <- ggplot(aes(x=x, y=y, label=lab), data=tmp) +
     geom_point() +
     geom_text(data=subset(tmp, x > 0), hjust=-0.5) +
     geom_text(data=subset(tmp, x <= 0), hjust=1.5)
print(p)

geom_text labeling http://img8.imageshack.us/img8/1056/geomtext.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文