简体   繁体   中英

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?

For example, consider this R code

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. 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).

You want the asp plotting parameter, for aspect ratio. Set asp = 1 in the call to curve() :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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