在GGPLOT中仅移动一些X轴标签
请参阅此图:
tibble(x = 0:10, y = rnorm(11)) %>%
ggplot(aes(x,y)) +
geom_point() +
scale_x_continuous(breaks = c(seq(0,10,2)/10, seq(2,10,1)))
轴开头的标签非常拥挤。有没有一种方法可以仅推下一些标签(例如c(0.2、0.6、0.8)
),以便所有标签都可以读取?奖励:从tick滴到那些被推下的标签(换句话说,刻度更长)。
我知道我可以使用vjust = -5
作为+ theme(axis.text.x = element_text(vjust = -5)))
,但这会推下所有标签。
See this plot:
tibble(x = 0:10, y = rnorm(11)) %>%
ggplot(aes(x,y)) +
geom_point() +
scale_x_continuous(breaks = c(seq(0,10,2)/10, seq(2,10,1)))
The labels in the beginning of the axis are very crowded. Is there a way to push down only some labels (e.g. those of c(0.2, 0.6, 0.8)
) so that all labels would be readable? Bonus: add a vertical line from ticks to those labels which have been pushed down (in other words make the tick longer).
I know I can use vjust = -5
as in + theme(axis.text.x = element_text(vjust = -5))
but that would push down all labels.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种非常简单的方法,它通过在Vector
X_TICKS
中的标签之前添加新的行字符\ n
来向下推下轴文本。在2022-03-30上由 reprex软件包(v2.0.1)
Here is a very simple method that pushes down the axis text by adding a new line character
\n
before the label in the vectorx_ticks
.Created on 2022-03-30 by the reprex package (v2.0.1)
如果您确实想要那些长刻度,这就是如何以困难的方式做到这一点
This is how to do it the hard way, if you really want those long ticks