I am using the Bioclim dataset for a maxent project right now, but I want to add demographic predictors along with climatic ones. I have the 19 layer raster data from Bioclim and I'm hoping to use the raster::addLayer function to add the demographic data (population density, etc). I'm having a hard time finding a dataset (I've found this one on gridded population density but I'm not sure how to use it) and if I did find one, I'm not sure how to integrate it into R (what I'm using now is a saved .Rdata file which has it loaded in already). This type of project is completely foreign to me.

My concern with any dataset is mismatching spatial resolutions between the layers when using maxent from the dismo package. Is this valid? Here's what I have from the Bioclim:

class       : RasterBrick 
dimensions  : 900, 2160, 1944000, 19  (nrow, ncol, ncell, nlayers)
resolution  : 0.1666667, 0.1666667  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 
data source : in memory

It looks like the resolution is 10 arc-minutes, and I see other datasets that are more fine grain. Can I convert from the fine to this coarse? The other problem is the extent of this dataset, it's a little larger than others, can I pad other raster data with blank cells to fit the -60:90 extent?

  • 1
    The advice provided by @TomNash will get your data aggregated to the same resolution and extent. However, there is no need to add the density to the stack/brick object for analysis and I would actually recommend against it. It is a very different data type and is effectively the response variable. Before conducting any type of analysis you also need to be aware of aggregation errors and change of support problems such as MAUP. These issues could easily invalidate your analysis and most examples of these statistical issues are illustrated on exactly this type of data. Apr 4, 2016 at 19:25

1 Answer 1


So I was able to take the data from the GPW link above and load that into R with simply raster("path to .bil file"). Converting resolution and dealing with the extent was pretty simple too. Here's how it originally looked:

class       : RasterLayer 
dimensions  : 3432, 8640, 29652480  (nrow, ncol, ncell)
resolution  : 0.04166667, 0.04166667  (x, y)
extent      : -180, 180, -58, 85  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : /path/to/glds00ag.bil 
names       : glds00ag 
values      : 0, 123083  (min, max)

Now a few lines will modify the raster to conform to how I want it.

pop.dens <- raster("/path/to/glds00ag.bil")
projection(pop.dens) <- "+proj=longlat +ellps=WGS84" # not sure if entirely necessary
e <- extent(-180,180,-60,90) # match the existing raster
pop.dens <- extend(pop.dens, e) # pad a few values to reach all Latitudes
pop.dens <- aggregate(pop.dens, fun=mean, fac=4) # multiply resolution by 4

Now I've got it aligned with the RasterBrick to which I want to combine it using the function addLayer(bioStack, pop.dens)

class       : RasterLayer 
dimensions  : 900, 2160, 1944000  (nrow, ncol, ncell)
resolution  : 0.1666667, 0.1666667  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 
data source : /path/to/tmp/file.bil
names       : glds00ag 
values      : 0, 23032.25  (min, max)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.