简体   繁体   中英

How do I add custom ranges and points in the axes of a Base R plot?

Let's consider a vector and plot it.

s1 <- sample(100:1000,32,replace = T)
plot(s1)

The plot I get has a Y-Axis that ranges from 0-1000 with points in the intervals of 200 (0,200,400,600,800,1000) and this is happening implicitly.

If I use ylim argument, apparently or to be honest, evidently, I can now have a custom range,

plot(s1,ylim = c(0,1500))

The points on Y Axis now are 0-1500 as indicated but with the points in the intervals of 500 (0,500,1000,1500), this is happening without my control.

My question, how can I have custom points with custom intervals on the X or Y axis?

use axis() to set your limits : on either x, y, or both

s1 <- sample(100:1000,32,replace = T)
plot(s1, yaxt = "n")                  # `yaxt` prevents y-axis labels to be printed
axis(2, yaxp=c(10, 1000, 10), las=2)  # 'las' helps to align the tick mark labels along the axis or perpendicular
# 'yaxp' helps to set the break points you desire. Learn more from ?par

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