Reputation: 43
I have this image pixel object, created using Spatstat package in R. The range of x-axis is [0,24], the range of y-axis is [28000, 29500]. When I plot it out in R studio, the graph looks very narrow as below:
I guess it is because the range of x-axis is too small compared to y's. What should I do to make the plot wider?
Upvotes: 0
Views: 602
Reputation: 2973
In the spatstat
package, spatial objects are always plotted isometrically. The plot uses the same physical scale for the x and y axes.
Spatial objects in spatstat
occupy a specific location and size in two-dimensional space. A pixel image (object of class "im"
) is associated with a rectangular region at a specific location in two-dimensional space with a specific width and height. If this region is long and thin, then the plotted image will be displayed as long and thin, and will not be rescaled to fit the screen or page.
If you want to stretch a pixel image in spatstat
, you need to transform it to another image, which will be defined on a different region of two-dimensional space.
You can do that with the spatstat
function affine
. In your example, if Z
is your original pixel image, you could do
A <- affine(Z, diag(c(60,1)))
The second argument is the transformation matrix, which in this case is just a stretch of the x axis by a factor of 60. (The transformation will stretch the domain of the image, and stretch each individual pixel, by a factor of 60 in the x direction. The number of pixels and the pixel values will be unchanged. No interpolation or other fudging will occur.)
See Chapters 3 and 4 in the spatstat book
Upvotes: 1