如何控制Y轴上的值的显示? [英] how to control the display of values on Y axis?

查看:42
本文介绍了如何控制Y轴上的值的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个文件需要绘制,但我注意到每个绘制的 Y 轴都不同(所有文件的值彼此接近).我希望绘图在 y 轴上显示所有文件的相同值.

I have several files that I need to plot but I noticed that with each plot Y axis is different(the values for all file are close to each other). I want the plot to display the values on y axis the same thing for all files.

例子

如果你在这里绘制 f,你只会在 y 轴上得到两个刻度 100 和 300

if you plot f here you would get two ticks 100 and 300 only on y axis

f=c(1:477)

plot(f)

如何告诉 R 在 Y 轴上不仅显示 100 和 300 之类的东西,还显示 100 200 300 400 之类的东西

How can I tell R to display some thing like 100 200 300 400 not only 100 and 300 on Y axis

推荐答案

绘图时,不要绘制 y 轴:

When plotting, don't plot the y axis:

plot(x,y,yaxt="n")

现在绘制 y 轴,指示刻度:

And now plot the y axis, indicating the ticks:

ticks<-c(100,200,300,400)
axis(2,at=ticks,labels=ticks)

如果您想确保所有图都在 y 轴上显示某个范围(例如从 0 到 500),您可以使用 ylim 强制它,如下所示:

If you want to make sure that all plots show some range in the y axis (e.g. from 0 to 500), you can force it with ylim like this:

plot(x,y,yaxt="n",ylim=c(0,500))

这篇关于如何控制Y轴上的值的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆