如何在R的图中自定义x轴? [重复]

时间:2022-04-20 01:02:26

This question already has an answer here:

这个问题在这里已有答案:

I would like to customize my own x-axis using plot in R. What i want is that the x-axis would display 40-52, then from 1-40 again, something in the attachment shown below. My data is from 2015 week 40 to 2018 week 4, and I have tried something like 2017_40 to 2018_4, but this will make the graph look really cramped. Thanks in advanced!

我想使用R中的绘图来自定义我自己的x轴。我想要的是x轴将显示40-52,然后再次显示1-40,如下所示的附件中的某些内容。我的数据是从2015年第40周到第201周第4周,我尝试过像2017_40到2018_4这样的东西,但这会使图形显得非常狭窄。先谢谢了!

如何在R的图中自定义x轴? [重复]

1 个解决方案

#1


1  

Use xaxt='n' in your plot to suppress printing the x-axis, then use axis to print whatever you want.

在绘图中使用xaxt ='n'来禁止打印x轴,然后使用轴打印任何您想要的内容。

x = 40:92
y = sin(x)
plot(x,y, ylim=c(-2,2), type='l', xaxt='n')

xlab = ifelse(x>52, x-52,x)
axis(side=1, at=40:92, labels=xlab)

如何在R的图中自定义x轴? [重复]

#1


1  

Use xaxt='n' in your plot to suppress printing the x-axis, then use axis to print whatever you want.

在绘图中使用xaxt ='n'来禁止打印x轴,然后使用轴打印任何您想要的内容。

x = 40:92
y = sin(x)
plot(x,y, ylim=c(-2,2), type='l', xaxt='n')

xlab = ifelse(x>52, x-52,x)
axis(side=1, at=40:92, labels=xlab)

如何在R的图中自定义x轴? [重复]