简体   繁体   English

R曲线的X和Y轴上的比例相同

[英]Same scale on X and Y axis in R curve

When I use R's curve() function, is there a way to force it to use the same scale on the X and the Y axis? 当我使用R的curve()函数时,是否有办法强迫它在X和Y轴上使用相同的比例?

For example, consider this R code 例如,考虑这个R代码

mean <- 5
variance <- 0.05
curve(exp((((x - mean) / variance)^2) * -0.5), mean - 2, mean + 2)

This will give me this plot: 这会给我这个情节:

绘制曲线图

As you can see, the X axis and the Y axis use different scales. 如您所见,X轴和Y轴使用不同的比例。 How can I fix this? 我怎样才能解决这个问题?

Note: I know I can manually specify the range of the Y axis (via ylim= ) but I'd rather not use this (as this would require adopting it whenever the function changes). 注意:我知道我可以手动指定Y轴的范围(通过ylim= ),但我宁愿不使用它(因为只要函数更改,就需要采用它)。

You want the asp plotting parameter, for aspect ratio. 您需要asp绘图参数,纵横比。 Set asp = 1 in the call to curve() : 在对curve()的调用中设置asp = 1

mean <- 5
variance <- 0.05
curve(exp((((x - mean) / variance)^2) * -0.5), mean - 2, mean + 2, asp = 1)

That will do it. 那样做。

It is not quite perfect if you want xlim == ylim or if you want better labelling of the axes, but asp gets the same scale on both axes. 如果你想要xlim == ylim或者你想要更好地标记轴,它不是很完美,但asp在两个轴上获得相同的比例。

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

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