I'm creating a map of Pakistan based on availability of satisfactory water supply at a district level.

Since it is difficult to collect reliable data for all districts, I would like for the final map to show whitespace where the column Condition is unavailable. My SPDF is named pak.

tm_shape(pak) + tm_polygons("Condition", palette = "-Reds")

Above is the command I am using presently to get the following output. I would essentially like for the grey space to not be plotted at all (not even the borders).

Water Delivery in Pakistan

  • 2
    You should explain where the tm_ functions come from (they're not part of base R). If possible you should try and make examples using data we can all use - in this case you might be able to create a similar problem to yours with one of the data sets included in the R spatial packages and setting some things to NA
    – Spacedman
    Oct 7 '16 at 7:23

This may be as simple as filtering the spatial data frame first, something like replacing part of your code with:

tm_shape(pak[!is.na(pak$Condition),]) ....

this should not only not plot the missing regions, there won't be a "missing" item in the legend either.

  • Hey, I figured out a cleaner way to do it. The new command is: tm_shape(pak) + tm_fill("Condition", colorNA = NULL) Oct 7 '16 at 10:41

Try this just to show the missing vs. not-missing polygons. You don't really need special packages to match values to colours with the sp plot functions and standar R tools.

plot(pak, col = ifelse(!is.na(pak$Condition), "red", "white"))

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.