0

I'm trying to use R (and R studio) to examine a GeoTIFF file that I've gotten from NASA's Socioeconomic Data and Applications Center (SEDAC).

I'm a complete beginner in GIS, so as a first step, I was trying to get R to load in the tif and plot the same map that I've seen rendered as a PNG on their site:

Population Count for 2020, as shown on the SEDAC website

I downloaded the data set from their page (though at a lower resolution, just to cut down on file size), and saved as pop-count-2020.tif in my R Studio workspace.

Then I ran this program:

install.packages(c("rgdal", "raster"))
library(raster)
library(rgdal)

pop_count_2020 <- raster(x = "pop-count-2020.tif")
plot(pop_count_2020)

And I'm seeing a plot like this:

My rendered R plot

I am getting some data rendered, which seems to line up with the darkest areas of the SEDAC original, so it feels like my scale is working at too large an increment, so most things are getting rounded down into the smallest bucket.

Is this actually what's happening or have I misunderstood?

If so, how can I correct this?

I'm not sure what to try next as I'm having a hard time trying to find the right terminology for what I'm trying to do.

  • Don't 'lower the resolution'. Each pixel has a specific spatial resolution (eg. 1km by 1km) and the pixel value represents how many people live in that area. If you need to change the raster resolution (to make it more easy to open with a gis package, a valid use case) you need to do some kind of aggregation. see pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/… – nickves May 12 at 21:02
  • @nickves, thanks for the warning! But meant that I choose a file that was already at a lower resolution from the data set available rather than modifying a download to be lower by hand – anotherdave May 13 at 12:19
  • Glad you were aware of that subtle difference. Now regarding your question, you could 'reclassify' the raster values to a set of predetermined groups (or bins). For this example, the first bin contains all the raster values that are less than 1. You can learn more about reclassifying here: pro.arcgis.com/en/pro-app/tool-reference/3d-analyst/… (Don't worry if the reference page is an ESRI page. The principals are the same regardless of what software you are using.) – nickves May 13 at 12:53
1

R has scaled the min-max of the data linearly to the colours in the palette. If you look at the key of the SEDAC map you can see it's far from linear:

enter image description here

You need to make a raster which has categorical values in those colour range bins.

Experiment: make a raster with number from 1 to 100:

> r = raster(matrix(1:100,10,10))
> plot(r)

enter image description here

Then cut it into some categories based on these breakpoints, and plot it using a colour palette:

> rc = cut(r,c(0,10,90,99,101))
> plot(rc,col=c("red","yellow","green","black"))

enter image description here

If you cut your raster to the categories in the legend of the SEDAC map, and can use a colour-picker to get the colours of the SEDAC plot from the legend, then you should end up with something in R that looks like that. You'll probably have to create a custom legend because as I've plotted it above the legend shows the category number (from 1 to 4 in my case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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