使用 coord_polar() 时旋转 x 轴文本
我有一个在极轴上有许多值的散点图 - coord_polar()。生成的图表包含拥挤的文本,因为文本始终与页面底部对齐。
是否可以放置文本,使其沿极 x 轴径向打印?
编辑提供一个示例:
qplot(data=presidential, name,end) + coord_polar()
在总统案例中,我希望看到总统的名字与他们所在的轴/辐条成一定角度。下面是我正在处理的图表示例,其中 x 轴是分类变量,y 轴是连续变量(与示例类似)。
I have a scatter-plot with many values on a polar axis - coord_polar(). The resulting graph has crowded text because the text is always aligned with the bottom of the page.
Is it possible to place the text so that it is printed radially along the polar x-axis?
Edited to provide an example:
qplot(data=presidential, name,end) + coord_polar()
In the presidential case I would like to see the presidential names angled to align with the axis/spoke they are on. Below is an example of the graph I am working on where the x axis is categorical and the y-axis is a continuous variable (similar to the example).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我知道这是一个老话题,但我发现了一个更好的解决方案来解决这个问题,灵感来自巴普蒂斯的评论:
I understand this is an old topic, but I found a better solution for this problem, inspired from baptise's comment:
Yoplait 的答案很有帮助,但仍然没有解决必须在图表的一半中颠倒阅读的问题。这张海报提出的想法的延伸如下。
首先准备角度向量,确保我们将图分成两部分:
现在我们可以附加角度向量来制作实际的图:
The answer by Yoplait helps a lot, but still does not solve the issue of having to read upside down in half of the graph. An extention of the idea that this poster proposes is as follows.
First prepare the angle vector, making sure we split the graph in two:
And now we can append the angle vectors to make the actual graph:
这是一个不太优雅的坐标示例:
here is a not elegant example of the coordinate:
编辑:现在是 ggplot2 3.5.0+ 的一部分
ggplot2 的开发版本刚刚添加了新的
coord_radial()
和guide_axis_theta()
,只需设置轴即可使此问题变得更容易角度。同样的策略也适用于将文本角度设置为圆的切线。
创建于 2023 年 11 月 20 日,使用 reprex v2.0.2
EDIT: now part of ggplot2 3.5.0+
The development version of ggplot2 just added a new
coord_radial()
andguide_axis_theta()
that makes this problem easier by just setting the axis angle.The same strategy also works for setting the text angle as a tangent to the circle.
Created on 2023-11-20 with reprex v2.0.2
你的reprex是一个有点特别困难的情况,x轴上有双布什和日期等等,所以我懒得让它工作,但是:看看< a href="https://allancameron.github.io/geomtextpath/" rel="nofollow noreferrer">geomtextpath 的
geom_textvline
,其工作方式类似于geom_vline 但带有文本。
Your reprex is a somewhat particularly difficult case, what with the double Bushs and Dates on the x-axis and all, so I couldn't be bothered to make it work for that, but: check out geomtextpath's
geom_textvline
, it works likegeom_vline
but with text.