简体   繁体   English

R:如何使用 ggplot 使刻度标签居中(在刻度线之间放置标签)?

[英]R: How to center the tick labels (putting labels between tick marks) using ggplot?

I was using R ggplot for data visualization, and I met the problem centering the tick labels between tick marks on x/y axes.我正在使用 R ggplot 进行数据可视化,我遇到了将刻度标签集中在 x/y 轴上刻度线之间的问题。 Here's a similar question but the implementation is matplotlib.这是一个类似的问题,但实现是 matplotlib。

This is what I had (the wrong version):这就是我所拥有的(错误的版本): 在此处输入图像描述

And this is what I expected:这就是我所期望的: 在此处输入图像描述

THANKS A LOT!!!多谢!!!

It is hard to reproduce your plot without the data you used to create the plot or the code you used to generate the plot如果没有用于创建 plot 的数据或用于生成 plot 的代码,很难重现您的 plot

You can move the x-axis labels to the right by adding the following code to your plot您可以通过将以下代码添加到 plot 来将 x 轴标签向右移动

+ theme(axis.text.x=element_text(hjust=-0.5))

Additionally, one option might be just to rotate the x-axis labels instead of moving them.此外,一种选择可能只是旋转 x 轴标签而不是移动它们。 You can do this by adding the following code您可以通过添加以下代码来做到这一点

+ theme(axis.text.x=element_text(angle = 90))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM