r - How can I have the full range in the x- and y-axis labels in a plot? -
i have 2 variables, x , y
x = runif(8, 0, runif(1, 1, 5)) y = x^2 that want plot. note range of x (and hence y=x^2) not same.
so, command
plot(x, y, pch=19, col='red') produces

however, don't want borders around graph, use bty='n' parameter plot:
plot(x, y, pch=19, col='red', bty='n') which produces

this bit unfortunate, imho, since i'd y-axis go way 4 , x-axis way 2.
so, ue xaxp , yaxp parameters in plot command:
plot(x, y, pch=19, col='red', bty='n', xaxp=c( floor (min(x)), ceiling(max(x)), 5 ), yaxp=c( floor (min(y)), ceiling(max(y)), 5 ) ) which produces 
this bit better, still doesn't show full range. also, thought nice default axis labaling uses steps 1,2,3,4 or 0.5,1,1.5,2, not arbitrary fractions.
i guess r has parameter or mechanism plot full range in axis in "humanly" fashion (0.5,1,1.5 ...) didn't find it. so, try?
try:
plot(x, y, pch=19, col='red', bty='n', xlim=c(min(x),max(x)), ylim=c(min(y),max(y)), axes=false) axis(1, at=seq(floor(min(x)), ceiling(max(x)), 0.5)) axis(2, at=seq(floor(min(y)), ceiling(max(y)), 0.5)) or if you'd prefer hard-code axis ranges:
axis(1, at=seq(0, 2, 0.5)) axis(2, at=seq(0, 4, 0.5)) is after?
Comments
Post a Comment