user7417
user7417

Reputation: 1581

Restrict box and axis to extent in plot.raster

When plotting a raster the box around the plot and the axes are adjusted automatically:

r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r)

Here, the extent is

extent(r)
class       : Extent 
xmin        : -180 
xmax        : 180 
ymin        : -90 
ymax        : 90

Nevertheless, the y-axis runs from -180 to 180 and there is ugly white space on the top and the bottom of the plot. Is there a way to force the box and the y-axis to the extent of the raster layer? I fumbled around with arguments like asp, ylim etc. but could not find any solution. Which way to do that am I missing?

Upvotes: 1

Views: 596

Answers (2)

Robert Hijmans
Robert Hijmans

Reputation: 47061

You are not saying what you are plotting to. For some devices, e.g. png you can set the height and width. In other cases, you need to resize the plotting window manually.

Upvotes: 1

Liman
Liman

Reputation: 1300

Try

plot(r, asp=NA)

to see if this is what you want. ?raster::plot

Upvotes: 1

Related Questions