在ggplot2中注释轴

发布于 2024-08-26 17:25:37 字数 597 浏览 3 评论 0原文

我正在寻找在 ggplot2 中注释轴的方法。问题的示例可以在这里找到: http://learnr.wordpress.com/2009/09/24/ggplot2-back-to-back-bar-charts

图表的 y 轴(链接中的示例图)有一个注释:(百万欧元)。有没有办法在 ggplot2 中创建此类注释?查看文档,没有明显的方法,因为 ggplot 没有明确让您将对象放置在绘图区域之外。但也许有一些解决方法?

我想到的可能的解决方法之一是使用秤:

data=data.frame(x=1:10,y=1:10)
qplot(x=x,y=y,data=data)+scale_y_continuous(breaks=10.1,label="Millions")

但是如何删除蜱虫呢?而且似乎由于 ggplot 不支持多个尺度,所以当它自动计算尺度时,我需要获取scale_y_连续的输出,然后手动添加我的自定义中断和标签。也许有更好的方法?

I am looking for the way to annotate axis in ggplot2. The example of the problem can be found here: http://learnr.wordpress.com/2009/09/24/ggplot2-back-to-back-bar-charts.

The y axis of the chart (example graph in the link) has an annotation: (million euro). Is there a way to create such types of annotations in ggplot2? Looking at the documentation there is no obvious way, since the ggplot does not explicitly let you put objects outside plotting area. But maybe there is some workaround?

One of the possible workarounds I thought about is using scales:

data=data.frame(x=1:10,y=1:10)
qplot(x=x,y=y,data=data)+scale_y_continuous(breaks=10.1,label="Millions")

But then how do I remove the tick? And it seems that since ggplot does not support multiple scales, I will need to grab the output of the scale_y_continuous, when it calculates the scales automaticaly and then add my custom break and label by hand. Maybe there is a better way?

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

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

发布评论

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

评论(1

盛夏尉蓝 2024-09-02 17:25:37

也许grid.text()

grid.text("label", x = unit(xpos, "npc"), y = unit(ypos, "npc"))

xposypos提供适当的值。

Maybe grid.text():

grid.text("label", x = unit(xpos, "npc"), y = unit(ypos, "npc"))

with appropriate values for xpos and ypos.

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