Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image plot function with aspect ratio 1 and ticks in axes

Tags:

r

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)

enter image description here But with the axes re-scaled to fit the image.

like image 898
alberto Avatar asked Sep 20 '25 18:09

alberto


1 Answers

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. 
like image 52
Roman Avatar answered Sep 22 '25 09:09

Roman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!