R如何控制轴标签上的零的十进制数字?

时间:2018-11-28 13:42:44

标签: r plot

轴标签上的零有时显示为“ 0.0”或“ 0.00”。如何调整不带小数位“ 0”的零。例如,我只想在下图的y轴上将“ 0.0”调整为“ 0”。enter image description here

plot(sin, -pi, 2*pi)

1 个答案:

答案 0 :(得分:1)

我们可以使用axis函数,并使用atlabels参数控制最终显示。

plot(sin, -pi, 2*pi, yaxt = 'n') # make sure to specify yaxt = 'n'
axis(side = 2, at = c(-1, -.5, 0, .5, 1), labels = c('-1', '-0.5', '0', '0.5', '1'))

enter image description here

相关问题