Given a squared matrix M, how can we plot it so that the aspect ratio is 1 and the axes are shown correctly?
I'm looking for this:
M <- t(replicate(50,sample(50, replace=TRUE)))
image(1:dim(M)[1], 1:dim(M)[1], M, col= gray((0:32)/32), asp=1)
But with the axes re-scaled to fit the image.
To change values at the axis you can use the axis
function and add axes=F
or xaxt="n"
in the image function to suppress the axis and/or the tick labels first.
image(1:dim(M)[1], 1:dim(M)[1], M, col= gray((0:32)/32), asp=1)
axis(1,1:50,1:50) # add a new x-axis
axis(2,1:50,1:50, pos=0) # add a y-axis with the coordinate zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With